From a7c1c83e8dccd3ae257c2597d9fc37a9b5c6ede9 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 15 Mar 2023 15:43:17 +0800 Subject: [PATCH] fix(nc-gui): return attachment url even fetch fails --- packages/nc-gui/composables/useAttachment.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/nc-gui/composables/useAttachment.ts b/packages/nc-gui/composables/useAttachment.ts index 7119d13c9d..009742da57 100644 --- a/packages/nc-gui/composables/useAttachment.ts +++ b/packages/nc-gui/composables/useAttachment.ts @@ -16,13 +16,17 @@ const useAttachment = () => { } const sources = getPossibleAttachmentSrc(item) for (const source of sources) { - // test if the source is accessible or not - const res = await fetch(source, { method: 'HEAD' }) - if (res.ok) { - return source - } + try { + // test if the source is accessible or not + const res = await fetch(source, { method: 'HEAD' }) + if (res.ok) { + return source + } + } catch {} } - return null + // if no source can be fetched, it could be probably blocked by CORS + // return original url or built url anyway + return item.url || `${appInfo.value.ncSiteUrl}/${item.path}` } const openAttachment = async (item: Record) => {