Browse Source

fix: avoid appending additional `jpeg` when filename ends with `jpg`

pull/7958/head
Pranav C 8 months ago
parent
commit
be4a2d6135
  1. 17
      packages/nocodb-sdk/src/lib/helperFunctions.ts

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

@ -112,13 +112,20 @@ function populateUniqueFileName(
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]}`;
let ext = mimeType.split('/')[1];
// avoid appending `jpeg` if extension is jpg
if(ext === 'jpeg' && fileName?.endsWith('.jpg')) {
ext = 'jpg'
}
if (!fileName?.endsWith(`.${ext}`)) {
fileName = `${fileName}.${ext}`;
} else if (
fileName?.endsWith(`.${mimeType.split('/')[1]}`) &&
fileName.length === `.${mimeType.split('/')[1]}`.length
fileName?.endsWith(`.${ext}`) &&
fileName.length === `.${ext}`.length
) {
fileName = `image.${mimeType.split('/')[1]}`;
fileName = `image.${ext}`;
}
const match = fileName.match(/^(.+?)(\((\d+)\))?(\.[^.]+)$/);

Loading…
Cancel
Save