Browse Source

refactor(nc-gui): getImageDataFromUrl function

pull/7605/head
Ramesh Mane 10 months ago
parent
commit
999bade32d
  1. 3
      packages/nc-gui/components/cell/attachment/utils.ts
  2. 8
      packages/nc-gui/utils/fileUtils.ts

3
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,

8
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]}`

Loading…
Cancel
Save