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; return { ...workspace, ...resolveRuntime(workspace), brand, offerings, trustContent: fallback.trustContent }; }); } 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 };