From e1a330a0a69123ec3824924acf127290b111fc2b Mon Sep 17 00:00:00 2001 From: X1a0t <405028157@qq.com> Date: Thu, 14 Sep 2023 16:56:55 +0800 Subject: [PATCH] fix: use cdn api when querying static CDN files (#4361) Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> --- packages/workspace/src/blob/cloud-blob-storage.ts | 8 ++++++-- packages/workspace/src/blob/local-static-storage.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/workspace/src/blob/cloud-blob-storage.ts b/packages/workspace/src/blob/cloud-blob-storage.ts index e13f3c45eb..d44dd8ec00 100644 --- a/packages/workspace/src/blob/cloud-blob-storage.ts +++ b/packages/workspace/src/blob/cloud-blob-storage.ts @@ -8,13 +8,17 @@ import { import { fetcher } from '@affine/workspace/affine/gql'; import type { BlobStorage } from '@blocksuite/store'; +import { predefinedStaticFiles } from './local-static-storage'; + export const createCloudBlobStorage = (workspaceId: string): BlobStorage => { return { crud: { get: async key => { + const suffix = predefinedStaticFiles.includes(key) + ? `/static/${key}` + : `/api/workspaces/${workspaceId}/blobs/${key}`; return fetchWithTraceReport( - runtimeConfig.serverUrlPrefix + - `/api/workspaces/${workspaceId}/blobs/${key}` + runtimeConfig.serverUrlPrefix + suffix ).then(res => { if (!res.ok) { // status not in the range 200-299 diff --git a/packages/workspace/src/blob/local-static-storage.ts b/packages/workspace/src/blob/local-static-storage.ts index 7e05bb9de8..575e82dff7 100644 --- a/packages/workspace/src/blob/local-static-storage.ts +++ b/packages/workspace/src/blob/local-static-storage.ts @@ -1,6 +1,6 @@ import type { BlobStorage } from '@blocksuite/store'; -const predefinedStaticFiles = [ +export const predefinedStaticFiles = [ 'v2yF7lY2L5rtorTtTmYFsoMb9dBPKs5M1y9cUKxcI1M=', 'nSEEkYxrThpZfLoPNOzMp6HWekvutAIYmADElDe1J6I=', 'CBWoKrhSDndjBJzscQKENRqiXOOZnzIA5qyiCoy4-A0=', @@ -29,7 +29,7 @@ export const createStaticStorage = (): BlobStorage => { return response.blob(); } } else if (predefinedStaticFiles.includes(key)) { - const response = await fetch(`/static/${key}.png`); + const response = await fetch(`/static/${key}`); if (response.ok) { return response.blob(); }