Browse Source

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

Nc fix/misc bugs
pull/7964/head
Pranav C 6 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(
fileName: string,
attachments: string[],
mimeType: string
attachments: string[]
) {
if (!mimeType) return 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.
if (!fileName?.endsWith(`.${mimeType.split('/')[1]}`)) {
fileName = `${fileName}.${mimeType.split('/')[1]}`;
} else if (
fileName?.endsWith(`.${mimeType.split('/')[1]}`) &&
fileName.length === `.${mimeType.split('/')[1]}`.length
) {
fileName = `image.${mimeType.split('/')[1]}`;
}
const match = fileName.match(/^(.+?)(\((\d+)\))?(\.[^.]+)$/);
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;
return fileName.replace(/^(.+?)(?:\((\d+)\))?(\.(?:tar|min)\.(?:\w{2,4})|\.\w+)$/, (fileName,name, count, ext) =>{
let genFileName = fileName;
let c = count || 1;
// iterate until a unique name
while (attachments.some((fn) => fn === genFileName)) {
genFileName = getFileName({
name,
ext,
count: c++
});
}
return genFileName;
});
}
export {

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

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

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

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

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

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

Loading…
Cancel
Save