Browse Source

Merge pull request #7958 from nocodb/nc-fix/misc-bugs

Nc fix/misc bugs
pull/7964/head
Pranav C 8 months ago committed by GitHub
parent
commit
4bd16f8efc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 47
      packages/nocodb-sdk/src/lib/helperFunctions.ts
  2. 2
      packages/nocodb/src/schema/swagger.json
  3. 11
      packages/nocodb/src/services/attachments.service.ts
  4. 1
      packages/nocodb/src/services/public-datas.service.ts

47
packages/nocodb-sdk/src/lib/helperFunctions.ts

@ -104,34 +104,31 @@ const getAvailableRollupForUiType = (type: string) => {
} }
}; };
const getFileName = ({
name,
count,
ext
}) => `${name}${count ? `(${count})` : ''}${ext? `${ext}` : ''}`
// add count before extension if duplicate name found
function populateUniqueFileName( function populateUniqueFileName(
fileName: string, fileName: string,
attachments: string[], attachments: string[]
mimeType: string
) { ) {
if (!mimeType) return fileName; return fileName.replace(/^(.+?)(?:\((\d+)\))?(\.(?:tar|min)\.(?:\w{2,4})|\.\w+)$/, (fileName,name, count, ext) =>{
let genFileName = fileName;
// If the file extension is not present, the while loop will go into an infinite loop. So, add the extension first if not present. let c = count || 1;
if (!fileName?.endsWith(`.${mimeType.split('/')[1]}`)) {
fileName = `${fileName}.${mimeType.split('/')[1]}`; // iterate until a unique name
} else if ( while (attachments.some((fn) => fn === genFileName)) {
fileName?.endsWith(`.${mimeType.split('/')[1]}`) && genFileName = getFileName({
fileName.length === `.${mimeType.split('/')[1]}`.length name,
) { ext,
fileName = `image.${mimeType.split('/')[1]}`; count: c++
} });
}
const match = fileName.match(/^(.+?)(\((\d+)\))?(\.[^.]+)$/); return genFileName;
});
if (!match) return fileName;
let c = !isNaN(parseInt(match[3])) ? parseInt(match[3]) : 1;
while (attachments.some((fn) => fn === fileName)) {
fileName = `${match[1]}(${c++})${match[4]}`;
}
return fileName;
} }
export { export {

2
packages/nocodb/src/schema/swagger.json

@ -16514,7 +16514,7 @@
} }
] ]
}, },
"put": { "patch": {
"summary": "Update Table Rows", "summary": "Update Table Rows",
"operationId": "db-data-table-row-update", "operationId": "db-data-table-row-update",
"responses": { "responses": {

11
packages/nocodb/src/services/attachments.service.ts

@ -43,7 +43,9 @@ export class AttachmentsService {
param.files?.map((file) => async () => { param.files?.map((file) => async () => {
try { try {
const originalName = utf8ify(file.originalname); const originalName = utf8ify(file.originalname);
const fileName = `${nanoid(18)}${path.extname(originalName)}`; const fileName = `${path.parse(originalName).name}_${nanoid(
5,
)}${path.extname(originalName)}`;
const url = await storageAdapter.fileCreate( const url = await storageAdapter.fileCreate(
slash(path.join(destPath, fileName)), slash(path.join(destPath, fileName)),
@ -140,10 +142,11 @@ export class AttachmentsService {
param.urls?.map?.((urlMeta) => async () => { param.urls?.map?.((urlMeta) => async () => {
try { try {
const { url, fileName: _fileName } = urlMeta; const { url, fileName: _fileName } = urlMeta;
const fileNameWithExt = _fileName || url.split('/').pop();
const fileName = `${nanoid(18)}${path.extname( const fileName = `${path.parse(fileNameWithExt).name}_${nanoid(
_fileName || url.split('/').pop(), 5,
)}`; )}${path.extname(fileNameWithExt)}`;
const attachmentUrl: string | null = const attachmentUrl: string | null =
await storageAdapter.fileCreateByUrl( await storageAdapter.fileCreateByUrl(

1
packages/nocodb/src/services/public-datas.service.ts

@ -326,7 +326,6 @@ export class PublicDatasService {
originalName = populateUniqueFileName( originalName = populateUniqueFileName(
originalName, originalName,
attachments[fieldName].map((att) => att?.title), attachments[fieldName].map((att) => att?.title),
file.mimetype,
); );
const fileName = `${nanoid(18)}${path.extname(originalName)}`; const fileName = `${nanoid(18)}${path.extname(originalName)}`;

Loading…
Cancel
Save