mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-04 19:11:57 +08:00
fix(core): linkpreview and imageproxy url should be prefixed with server url (#9838)
fix AF-2150
This commit is contained in:
+16
-4
@@ -1,5 +1,6 @@
|
|||||||
import { useRefEffect } from '@affine/component';
|
import { useRefEffect } from '@affine/component';
|
||||||
import { EditorLoading } from '@affine/component/page-detail-skeleton';
|
import { EditorLoading } from '@affine/component/page-detail-skeleton';
|
||||||
|
import { ServerService } from '@affine/core/modules/cloud';
|
||||||
import {
|
import {
|
||||||
customImageProxyMiddleware,
|
customImageProxyMiddleware,
|
||||||
type DocMode,
|
type DocMode,
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
import { DisposableGroup } from '@blocksuite/affine/global/utils';
|
import { DisposableGroup } from '@blocksuite/affine/global/utils';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
||||||
import type { Store } from '@blocksuite/affine/store';
|
import type { Store } from '@blocksuite/affine/store';
|
||||||
|
import { useService } from '@toeverything/infra';
|
||||||
import type { CSSProperties } from 'react';
|
import type { CSSProperties } from 'react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
@@ -47,6 +49,8 @@ const BlockSuiteEditorImpl = ({
|
|||||||
};
|
};
|
||||||
}, [page]);
|
}, [page]);
|
||||||
|
|
||||||
|
const server = useService(ServerService).server;
|
||||||
|
|
||||||
const editorRef = useRefEffect(
|
const editorRef = useRefEffect(
|
||||||
(editor: AffineEditorContainer) => {
|
(editor: AffineEditorContainer) => {
|
||||||
globalThis.currentEditor = editor;
|
globalThis.currentEditor = editor;
|
||||||
@@ -63,14 +67,22 @@ const BlockSuiteEditorImpl = ({
|
|||||||
// host should be ready
|
// host should be ready
|
||||||
|
|
||||||
// provide image proxy endpoint to blocksuite
|
// 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(
|
editor.host?.std.clipboard.use(
|
||||||
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
|
customImageProxyMiddleware(imageProxyUrl)
|
||||||
);
|
);
|
||||||
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
|
ImageBlockService.setImageProxyURL(imageProxyUrl);
|
||||||
|
|
||||||
editor.host?.doc
|
editor.host?.doc
|
||||||
.get(LinkPreviewerService)
|
.get(LinkPreviewerService)
|
||||||
.setEndpoint(BUILD_CONFIG.linkPreviewUrl);
|
.setEndpoint(linkPreviewUrl);
|
||||||
|
|
||||||
return editor.host?.updateComplete;
|
return editor.host?.updateComplete;
|
||||||
})
|
})
|
||||||
@@ -91,7 +103,7 @@ const BlockSuiteEditorImpl = ({
|
|||||||
disposableGroup.dispose();
|
disposableGroup.dispose();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[onEditorReady, page]
|
[onEditorReady, page, server]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { DetailPageWrapper } from '@affine/core/desktop/pages/workspace/detail-p
|
|||||||
import { PageHeader } from '@affine/core/mobile/components';
|
import { PageHeader } from '@affine/core/mobile/components';
|
||||||
import { useGlobalEvent } from '@affine/core/mobile/hooks/use-global-events';
|
import { useGlobalEvent } from '@affine/core/mobile/hooks/use-global-events';
|
||||||
import { AIButtonService } from '@affine/core/modules/ai-button';
|
import { AIButtonService } from '@affine/core/modules/ai-button';
|
||||||
|
import { ServerService } from '@affine/core/modules/cloud';
|
||||||
import { DocService } from '@affine/core/modules/doc';
|
import { DocService } from '@affine/core/modules/doc';
|
||||||
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
|
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
|
||||||
import { EditorService } from '@affine/core/modules/editor';
|
import { EditorService } from '@affine/core/modules/editor';
|
||||||
@@ -142,21 +143,29 @@ const DetailPageImpl = () => {
|
|||||||
const title = useLiveData(doc.title$);
|
const title = useLiveData(doc.title$);
|
||||||
usePageDocumentTitle(title);
|
usePageDocumentTitle(title);
|
||||||
|
|
||||||
|
const server = useService(ServerService).server;
|
||||||
|
|
||||||
const onLoad = useCallback(
|
const onLoad = useCallback(
|
||||||
(editorContainer: AffineEditorContainer) => {
|
(editorContainer: AffineEditorContainer) => {
|
||||||
// blocksuite editor host
|
// blocksuite editor host
|
||||||
const editorHost = editorContainer.host;
|
const editorHost = editorContainer.host;
|
||||||
|
|
||||||
// provide image proxy endpoint to blocksuite
|
// provide image proxy endpoint to blocksuite
|
||||||
editorHost?.std.clipboard.use(
|
const imageProxyUrl = new URL(
|
||||||
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
|
BUILD_CONFIG.imageProxyUrl,
|
||||||
);
|
server.baseUrl
|
||||||
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
|
).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
|
// provide link preview endpoint to blocksuite
|
||||||
editorHost?.doc
|
editorHost?.doc.get(LinkPreviewerService).setEndpoint(linkPreviewUrl);
|
||||||
.get(LinkPreviewerService)
|
|
||||||
.setEndpoint(BUILD_CONFIG.linkPreviewUrl);
|
|
||||||
|
|
||||||
// provide page mode and updated date to blocksuite
|
// provide page mode and updated date to blocksuite
|
||||||
const refNodeService = editorHost?.std.getOptional(RefNodeSlotsProvider);
|
const refNodeService = editorHost?.std.getOptional(RefNodeSlotsProvider);
|
||||||
@@ -190,7 +199,7 @@ const DetailPageImpl = () => {
|
|||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[docCollection.id, editor, jumpToPageBlock, openPage]
|
[docCollection.id, editor, jumpToPageBlock, openPage, server]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user