Browse Source

fix: drop url availability check with fetch

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5046/head
mertmit 2 years ago
parent
commit
947f4c7cb3
  1. 12
      packages/nc-gui/components/cell/attachment/utils.ts
  2. 12
      packages/nc-gui/composables/useKanbanViewStore.ts
  3. 12
      packages/nc-gui/composables/useViewData.ts

12
packages/nc-gui/components/cell/attachment/utils.ts

@ -237,17 +237,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
// if path doesn't exist, use `item.url` // if path doesn't exist, use `item.url`
if (path) { if (path) {
// try ${appInfo.value.ncSiteUrl}/${item.path} first // try ${appInfo.value.ncSiteUrl}/${item.path} first
const url = `${appInfo.value.ncSiteUrl}/${item.path}` return Promise.resolve(`${appInfo.value.ncSiteUrl}/${item.path}`)
try {
const res = await fetch(url)
if (res.ok) {
// use `url` if it is accessible
return Promise.resolve(url)
}
} catch {
// for some cases, `url` is not accessible as expected
// do nothing here
}
} }
// if it fails, use the original url // if it fails, use the original url
return Promise.resolve(item.url) return Promise.resolve(item.url)

12
packages/nc-gui/composables/useKanbanViewStore.ts

@ -149,17 +149,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
// if path doesn't exist, use `item.url` // if path doesn't exist, use `item.url`
if (path) { if (path) {
// try ${appInfo.value.ncSiteUrl}/${item.path} first // try ${appInfo.value.ncSiteUrl}/${item.path} first
const url = `${appInfo.value.ncSiteUrl}/${item.path}` return Promise.resolve(`${appInfo.value.ncSiteUrl}/${item.path}`)
try {
const res = await fetch(url)
if (res.ok) {
// use `url` if it is accessible
return Promise.resolve(url)
}
} catch {
// for some cases, `url` is not accessible as expected
// do nothing here
}
} }
// if it fails, use the original url // if it fails, use the original url
return Promise.resolve(item.url) return Promise.resolve(item.url)

12
packages/nc-gui/composables/useViewData.ts

@ -207,17 +207,7 @@ export function useViewData(
// if path doesn't exist, use `item.url` // if path doesn't exist, use `item.url`
if (path) { if (path) {
// try ${appInfo.value.ncSiteUrl}/${item.path} first // try ${appInfo.value.ncSiteUrl}/${item.path} first
const url = `${appInfo.ncSiteUrl}/${item.path}` return Promise.resolve(`${appInfo.ncSiteUrl}/${item.path}`)
try {
const res = await fetch(url)
if (res.ok) {
// use `url` if it is accessible
return Promise.resolve(url)
}
} catch {
// for some cases, `url` is not accessible as expected
// do nothing here
}
} }
// if it fails, use the original url // if it fails, use the original url
return Promise.resolve(item.url) return Promise.resolve(item.url)

Loading…
Cancel
Save