fix(core): fix doc url parsing with custom domain names (#10444)

Closes: [AF-2279](https://affine-pro.slack.com/archives/C06CTBH5L4R/p1740552397245649?thread_ts=1740547457.278239&cid=C06CTBH5L4R)
This commit is contained in:
fundon
2025-02-26 07:35:25 +00:00
parent e38e59d4e5
commit 866b096304
2 changed files with 7 additions and 4 deletions
@@ -11,9 +11,11 @@ import type { FrameworkProvider } from '@toeverything/infra';
function patchParseDocUrlExtension(framework: FrameworkProvider) { function patchParseDocUrlExtension(framework: FrameworkProvider) {
const workspaceService = framework.get(WorkspaceService); const workspaceService = framework.get(WorkspaceService);
const workspaceServerService = framework.get(WorkspaceServerService);
const baseUrl = workspaceServerService.server?.baseUrl ?? location.origin;
const ParseDocUrl = ParseDocUrlExtension({ const ParseDocUrl = ParseDocUrlExtension({
parseDocUrl(url) { parseDocUrl(url) {
const info = resolveLinkToDoc(url); const info = resolveLinkToDoc(url, baseUrl);
if (!info || info.workspaceId !== workspaceService.workspace.id) return; if (!info || info.workspaceId !== workspaceService.workspace.id) return;
delete info.refreshKey; delete info.refreshKey;
@@ -28,13 +30,14 @@ function patchParseDocUrlExtension(framework: FrameworkProvider) {
function patchGenerateDocUrlExtension(framework: FrameworkProvider) { function patchGenerateDocUrlExtension(framework: FrameworkProvider) {
const workspaceService = framework.get(WorkspaceService); const workspaceService = framework.get(WorkspaceService);
const workspaceServerService = framework.get(WorkspaceServerService); const workspaceServerService = framework.get(WorkspaceServerService);
const baseUrl = workspaceServerService.server?.baseUrl ?? location.origin;
const GenerateDocUrl = GenerateDocUrlExtension({ const GenerateDocUrl = GenerateDocUrlExtension({
generateDocUrl(pageId: string, params?: ReferenceParams) { generateDocUrl(pageId: string, params?: ReferenceParams) {
return generateUrl({ return generateUrl({
...params, ...params,
pageId, pageId,
workspaceId: workspaceService.workspace.id, workspaceId: workspaceService.workspace.id,
baseUrl: workspaceServerService.server?.baseUrl ?? location.origin, baseUrl,
}); });
}, },
}); });
@@ -102,8 +102,8 @@ const isRouteModulePath = (
): path is (typeof routeModulePaths)[number] => ): path is (typeof routeModulePaths)[number] =>
routeModulePaths.includes(path as any); routeModulePaths.includes(path as any);
export const resolveLinkToDoc = (href: string) => { export const resolveLinkToDoc = (href: string, baseUrl?: string) => {
const meta = resolveRouteLinkMeta(href); const meta = resolveRouteLinkMeta(href, baseUrl);
if (!meta || meta.moduleName !== 'doc') return null; if (!meta || meta.moduleName !== 'doc') return null;
const params = preprocessParams( const params = preprocessParams(