53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
const { request } = require("./request");
|
|
const fallback = require("./linjing-data");
|
|
const { resolveRuntime } = require("./module-registry");
|
|
|
|
function toOffering(item) {
|
|
const config = item && item.config && typeof item.config === "object" ? item.config : {};
|
|
return {
|
|
...item,
|
|
id: item.id,
|
|
category: item.category || item.kind || "业务提供项",
|
|
name: item.name,
|
|
desc: item.summary || item.description || "",
|
|
image: item.coverUrl || item.image || "",
|
|
priceRange: item.priceText || "沟通报价",
|
|
keywords: Array.isArray(config.keywords) ? config.keywords : [],
|
|
};
|
|
}
|
|
|
|
function loadWorkspace() {
|
|
return request("/public/workspace").then((workspace) => {
|
|
const brand = workspace && workspace.brand ? workspace.brand : fallback.brand;
|
|
const offerings = Array.isArray(workspace && workspace.offerings)
|
|
? workspace.offerings.map(toOffering)
|
|
: fallback.offerings;
|
|
const trustContent =
|
|
Array.isArray(workspace && workspace.trustContent) && workspace.trustContent.length
|
|
? workspace.trustContent
|
|
: fallback.trustContent;
|
|
return {
|
|
...workspace,
|
|
...resolveRuntime(workspace),
|
|
brand,
|
|
offerings,
|
|
trustContent,
|
|
plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [],
|
|
};
|
|
});
|
|
}
|
|
|
|
function loadWorkspaceWithFallback() {
|
|
return loadWorkspace().catch(() => ({
|
|
schemaVersion: "static-fallback",
|
|
brand: fallback.brand,
|
|
offerings: fallback.offerings,
|
|
trustContent: fallback.trustContent,
|
|
capabilities: [],
|
|
theme: resolveRuntime({}).theme,
|
|
modules: [],
|
|
}));
|
|
}
|
|
|
|
module.exports = { loadWorkspaceWithFallback };
|