diff --git a/packages/nc-gui/components/cell/attachment/utils.ts b/packages/nc-gui/components/cell/attachment/utils.ts index 25e265ed0c..d669f0760f 100644 --- a/packages/nc-gui/components/cell/attachment/utils.ts +++ b/packages/nc-gui/components/cell/attachment/utils.ts @@ -13,7 +13,6 @@ import { extractImageSrcFromRawHtml, inject, isImage, - isImageUrl, message, parseProp, ref, @@ -332,7 +331,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( mimetype: response.headers.get('content-type') || undefined, size: +(response.headers.get('content-length') || 0) || undefined, } as { minetype?: string; size?: number } - } else if (isImageUrl(imageUrl)) { + } else if (imageUrl.slice(imageUrl.lastIndexOf('.') + 1).toLowerCase().length) { return { mimetype: `image/${imageUrl.slice(imageUrl.lastIndexOf('.') + 1).toLowerCase()}`, size: +(response.headers.get('content-length') || 0) || undefined, diff --git a/packages/nc-gui/utils/fileUtils.ts b/packages/nc-gui/utils/fileUtils.ts index c81334d1ae..c7a6a1a913 100644 --- a/packages/nc-gui/utils/fileUtils.ts +++ b/packages/nc-gui/utils/fileUtils.ts @@ -19,11 +19,7 @@ const isImage = (name: string, mimetype?: string) => { return imageExt.some((e) => name?.toLowerCase().endsWith(`.${e}`)) || mimetype?.startsWith('image/') } -const isImageUrl = (url: string) => { - return imageExt.some((e) => url?.toLowerCase().endsWith(`.${e}`)) -} - -export { isImage, imageExt, isImageUrl } +export { isImage, imageExt } // Ref : https://stackoverflow.com/a/12002275 // Tested in Mozilla Firefox browser, Chrome @@ -83,6 +79,8 @@ export function extractImageSrcFromRawHtml(rawText: string) { } export function populateUniqueFileName(fn: string, attachments: any[], mimeType: string) { + if (!mimeType) return fn + // If the image extension is not present, the while loop will go into an infinite loop. So, add the extension first if not present. if (!fn?.endsWith(mimeType.split('/')[1])) { fn = `${fn}.${mimeType.split('/')[1]}`