fix: 补全小程序媒体地址并支持构建注入 AppID

This commit is contained in:
que01 committed 2026-10-13 09:51:38 +08:00
1 parent 5c6ad02f46
commit 07629a4596
4 files changed
+18 -10

No files matched your search

+15 -1
View File
@@ -47,7 +47,7 @@ export async function loadWorkspace() {
const data = await request<RuntimeWorkspace>("/public/workspace");
const editorPreview = isEditorPreview();
if (!editorPreview && data.publication?.status !== "published") throw new Error("品牌尚未发布");
return {
return resolveMediaUrls({
...data,
brand: data.brand ?? {},
templateData: data.templateData ?? {},
@@ -58,7 +58,21 @@ export async function loadWorkspace() {
capabilities: data.capabilities ?? [],
theme: data.theme ?? { colors: {} },
plugins: data.plugins ?? [],
});
}
function resolveMediaUrls(workspace: RuntimeWorkspace): RuntimeWorkspace {
const resolve = (value: unknown): unknown => {
if (typeof value === "string") {
return value.startsWith("/media/") ? `${API_BASE_URL.replace(/\/$/, "")}${value}` : value;
}
if (Array.isArray(value)) return value.map(resolve);
if (value && typeof value === "object") {
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolve(item)]));
}
return value;
};
return resolve(workspace) as RuntimeWorkspace;
}
export async function ensureSession() {
if (hasSession()) return;