fix: harden wiki delivery and leaderboard performance
This commit is contained in:
1 parent
0c5e2e8cb0
commit
9f29ecae9e
28 files changed
+616
-68
No files matched your search
@@ -27,6 +27,16 @@ export type KnowledgeSourceLike = {
|
||||
slug?: string | null;
|
||||
};
|
||||
|
||||
/** Build a HashRouter URL without dropping a reverse-proxy path such as /web/. */
|
||||
export function buildAppHashUrl(path: string): string {
|
||||
const route = path.startsWith("/") ? path : `/${path}`;
|
||||
if (typeof window !== "undefined") {
|
||||
return `${window.location.pathname || "/"}#${route}`;
|
||||
}
|
||||
const base = import.meta.env.BASE_URL || "/";
|
||||
return `${base}#${route}`;
|
||||
}
|
||||
|
||||
export function parseWeKnoraPreviewUrl(url?: string | null): WeKnoraSourceTarget | null {
|
||||
if (!url?.startsWith("/weknora-source-preview?")) {
|
||||
return null;
|
||||
@@ -92,7 +102,7 @@ export function buildWeKnoraSourceIframeUrl(target: WeKnoraSourceTarget): string
|
||||
if (target.documentId) params.set("documentId", target.documentId);
|
||||
if (target.wikiSlug) params.set("wikiSlug", target.wikiSlug);
|
||||
const query = params.toString();
|
||||
return `/#/page/workspace/knowledge/${encodeURIComponent(target.knowledgeBaseId)}${query ? `?${query}` : ""}`;
|
||||
return buildAppHashUrl(`/page/workspace/knowledge/${encodeURIComponent(target.knowledgeBaseId)}${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +113,7 @@ export function buildWeKnoraWikiPageUrl(
|
||||
knowledgeBaseId: string,
|
||||
wikiSlug: string,
|
||||
): string {
|
||||
return `/#${buildWeKnoraWikiPagePath(knowledgeBaseId, wikiSlug)}`;
|
||||
return buildAppHashUrl(buildWeKnoraWikiPagePath(knowledgeBaseId, wikiSlug));
|
||||
}
|
||||
|
||||
export function buildWeKnoraWikiPagePath(
|
||||
@@ -129,7 +139,7 @@ export function buildPublicKnowledgeWikiUrl(
|
||||
knowledgeBaseId: string,
|
||||
wikiSlug?: string,
|
||||
): string {
|
||||
return `/#${buildPublicKnowledgeWikiPath(knowledgeBaseId, wikiSlug)}`;
|
||||
return buildAppHashUrl(buildPublicKnowledgeWikiPath(knowledgeBaseId, wikiSlug));
|
||||
}
|
||||
|
||||
export function buildLegacyKnowledgeSourceUrl(source: KnowledgeSourceLike): string {
|
||||
@@ -160,6 +170,7 @@ export function normalizeMalformedWeKnoraHashRoute(): boolean {
|
||||
const { pathname, search, hash } = window.location;
|
||||
if (!pathname.startsWith("/page/workspace/knowledge/")) return false;
|
||||
if (hash && !hash.startsWith("#/")) return false;
|
||||
window.location.replace(`/#${pathname}${search}`);
|
||||
const base = import.meta.env.BASE_URL || "/";
|
||||
window.location.replace(`${base}#${pathname}${search}`);
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user