refactor: 按模板隔离小程序 fallback 数据
This commit is contained in:
1 parent
bfa24d48d0
commit
b525c4d29a
2 files changed
+36
-10
No files matched your search
@@ -1,5 +1,5 @@
|
||||
const { request } = require("./request");
|
||||
const fallback = require("./linjing-data");
|
||||
const { getFallbackWorkspace } = require("./fallback-workspaces");
|
||||
const { resolveRuntime } = require("./module-registry");
|
||||
|
||||
function toOffering(item) {
|
||||
@@ -18,6 +18,9 @@ function toOffering(item) {
|
||||
|
||||
function loadWorkspace() {
|
||||
return request("/public/workspace").then((workspace) => {
|
||||
const fallback = getFallbackWorkspace(
|
||||
workspace && workspace.template && workspace.template.key,
|
||||
);
|
||||
const brand = workspace && workspace.brand ? workspace.brand : fallback.brand;
|
||||
const offerings = Array.isArray(workspace && workspace.offerings)
|
||||
? workspace.offerings.map(toOffering)
|
||||
@@ -38,15 +41,7 @@ function loadWorkspace() {
|
||||
}
|
||||
|
||||
function loadWorkspaceWithFallback() {
|
||||
return loadWorkspace().catch(() => ({
|
||||
schemaVersion: "static-fallback",
|
||||
brand: fallback.brand,
|
||||
offerings: fallback.offerings,
|
||||
trustContent: fallback.trustContent,
|
||||
capabilities: [],
|
||||
theme: resolveRuntime({}).theme,
|
||||
modules: [],
|
||||
}));
|
||||
return loadWorkspace().catch(() => getFallbackWorkspace("personal"));
|
||||
}
|
||||
|
||||
module.exports = { loadWorkspaceWithFallback };
|
||||
Reference in new issue
Block a user