feat: use custom image/preview link (#5584)

dep toeverything/blocksuite#5969
This commit is contained in:
DarkSky
2024-01-23 08:53:56 +00:00
parent 62169c59c8
commit 8bbe2e3bb1
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -19,6 +19,7 @@ export const runtimeFlagsSchema = z.object({
downloadUrl: z.string(), downloadUrl: z.string(),
// see: tools/workers // see: tools/workers
imageProxyUrl: z.string(), imageProxyUrl: z.string(),
linkPreviewUrl: z.string(),
enablePreloading: z.boolean(), enablePreloading: z.boolean(),
enableNewSettingModal: z.boolean(), enableNewSettingModal: z.boolean(),
enableNewSettingUnstableApi: z.boolean(), enableNewSettingUnstableApi: z.boolean(),
@@ -19,6 +19,7 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
changelogUrl: 'https://affine.pro/what-is-new', changelogUrl: 'https://affine.pro/what-is-new',
downloadUrl: 'https://affine.pro/download', downloadUrl: 'https://affine.pro/download',
imageProxyUrl: '/api/worker/image-proxy', imageProxyUrl: '/api/worker/image-proxy',
linkPreviewUrl: '/api/worker/link-preview',
enablePreloading: true, enablePreloading: true,
enableNewSettingModal: true, enableNewSettingModal: true,
enableNewSettingUnstableApi: false, enableNewSettingUnstableApi: false,
@@ -61,6 +62,7 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases', changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
downloadUrl: 'https://affine.pro/download', downloadUrl: 'https://affine.pro/download',
imageProxyUrl: '/api/worker/image-proxy', imageProxyUrl: '/api/worker/image-proxy',
linkPreviewUrl: '/api/worker/link-preview',
enablePreloading: true, enablePreloading: true,
enableNewSettingModal: true, enableNewSettingModal: true,
enableNewSettingUnstableApi: false, enableNewSettingUnstableApi: false,
@@ -5,6 +5,11 @@ import { useWorkspaceStatus } from '@affine/core/hooks/use-workspace-status';
import { waitForCurrentWorkspaceAtom } from '@affine/core/modules/workspace'; import { waitForCurrentWorkspaceAtom } from '@affine/core/modules/workspace';
import { WorkspaceSubPath } from '@affine/core/shared'; import { WorkspaceSubPath } from '@affine/core/shared';
import { globalBlockSuiteSchema, SyncEngineStep } from '@affine/workspace'; import { globalBlockSuiteSchema, SyncEngineStep } from '@affine/workspace';
import {
BookmarkService,
customImageProxyMiddleware,
ImageService,
} from '@blocksuite/blocks';
import type { AffineEditorContainer } from '@blocksuite/presets'; import type { AffineEditorContainer } from '@blocksuite/presets';
import type { Page, Workspace } from '@blocksuite/store'; import type { Page, Workspace } from '@blocksuite/store';
import { appSettingAtom } from '@toeverything/infra/atom'; import { appSettingAtom } from '@toeverything/infra/atom';
@@ -138,6 +143,13 @@ const DetailPageImpl = memo(function DetailPageImpl({ page }: { page: Page }) {
); );
} }
} catch {} } catch {}
ImageService.setImageProxyURL(runtimeConfig.imageProxyUrl);
BookmarkService.setLinkPreviewEndpoint(runtimeConfig.linkPreviewUrl);
editor.host?.std.clipboard.use(
customImageProxyMiddleware(runtimeConfig.imageProxyUrl)
);
setPageMode(currentPageId, mode); setPageMode(currentPageId, mode);
// fixme: it seems pageLinkClicked is not triggered sometimes? // fixme: it seems pageLinkClicked is not triggered sometimes?
const dispose = editor.slots.pageLinkClicked.on(({ pageId }) => { const dispose = editor.slots.pageLinkClicked.on(({ pageId }) => {