Skip to content

Commit

Permalink
fix(core): linkpreview and imageproxy url should be prefixed with ser…
Browse files Browse the repository at this point in the history
…ver url (#9838)

fix AF-2150
  • Loading branch information
pengx17 committed Jan 22, 2025
1 parent 795c5c9 commit 08f6a22
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRefEffect } from '@affine/component';
import { EditorLoading } from '@affine/component/page-detail-skeleton';
import { ServerService } from '@affine/core/modules/cloud';
import {
customImageProxyMiddleware,
type DocMode,
Expand All @@ -9,6 +10,7 @@ import {
import { DisposableGroup } from '@blocksuite/affine/global/utils';
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
import type { Store } from '@blocksuite/affine/store';
import { useService } from '@toeverything/infra';
import type { CSSProperties } from 'react';
import { useEffect, useState } from 'react';

Expand Down Expand Up @@ -47,6 +49,8 @@ const BlockSuiteEditorImpl = ({
};
}, [page]);

const server = useService(ServerService).server;

const editorRef = useRefEffect(
(editor: AffineEditorContainer) => {
globalThis.currentEditor = editor;
Expand All @@ -63,14 +67,22 @@ const BlockSuiteEditorImpl = ({
// host should be ready

// provide image proxy endpoint to blocksuite
const imageProxyUrl = new URL(
BUILD_CONFIG.imageProxyUrl,
server.baseUrl
).toString();
const linkPreviewUrl = new URL(
BUILD_CONFIG.linkPreviewUrl,
server.baseUrl
).toString();
editor.host?.std.clipboard.use(
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
customImageProxyMiddleware(imageProxyUrl)
);
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
ImageBlockService.setImageProxyURL(imageProxyUrl);

editor.host?.doc
.get(LinkPreviewerService)
.setEndpoint(BUILD_CONFIG.linkPreviewUrl);
.setEndpoint(linkPreviewUrl);

return editor.host?.updateComplete;
})
Expand All @@ -91,7 +103,7 @@ const BlockSuiteEditorImpl = ({
disposableGroup.dispose();
};
},
[onEditorReady, page]
[onEditorReady, page, server]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DetailPageWrapper } from '@affine/core/desktop/pages/workspace/detail-p
import { PageHeader } from '@affine/core/mobile/components';
import { useGlobalEvent } from '@affine/core/mobile/hooks/use-global-events';
import { AIButtonService } from '@affine/core/modules/ai-button';
import { ServerService } from '@affine/core/modules/cloud';
import { DocService } from '@affine/core/modules/doc';
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
import { EditorService } from '@affine/core/modules/editor';
Expand Down Expand Up @@ -142,21 +143,29 @@ const DetailPageImpl = () => {
const title = useLiveData(doc.title$);
usePageDocumentTitle(title);

const server = useService(ServerService).server;

const onLoad = useCallback(
(editorContainer: AffineEditorContainer) => {
// blocksuite editor host
const editorHost = editorContainer.host;

// provide image proxy endpoint to blocksuite
editorHost?.std.clipboard.use(
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
);
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
const imageProxyUrl = new URL(
BUILD_CONFIG.imageProxyUrl,
server.baseUrl
).toString();

const linkPreviewUrl = new URL(
BUILD_CONFIG.linkPreviewUrl,
server.baseUrl
).toString();

editorHost?.std.clipboard.use(customImageProxyMiddleware(imageProxyUrl));
ImageBlockService.setImageProxyURL(imageProxyUrl);

// provide link preview endpoint to blocksuite
editorHost?.doc
.get(LinkPreviewerService)
.setEndpoint(BUILD_CONFIG.linkPreviewUrl);
editorHost?.doc.get(LinkPreviewerService).setEndpoint(linkPreviewUrl);

// provide page mode and updated date to blocksuite
const refNodeService = editorHost?.std.getOptional(RefNodeSlotsProvider);
Expand Down Expand Up @@ -190,7 +199,7 @@ const DetailPageImpl = () => {
disposable.dispose();
};
},
[docCollection.id, editor, jumpToPageBlock, openPage]
[docCollection.id, editor, jumpToPageBlock, openPage, server]
);

return (
Expand Down

0 comments on commit 08f6a22

Please sign in to comment.