Fix BIM share settings persistence on server

This commit is contained in:
CODEX 2026-07-02 20:47:20 +03:00
parent 2f1c7d979a
commit c242e364bb
1 changed files with 20 additions and 4 deletions

View File

@ -1940,6 +1940,21 @@ const handleLogout = (req, res, {redirect = true} = {}) => {
res.end("<!doctype html><html><head><meta charset='utf-8'></head><body>NODE.DC BIM session closed.</body></html>");
};
const normalizeViewerSettings = (value) => (
value && typeof value === "object" && !Array.isArray(value)
? value
: null
);
const readViewerSettingsForModelSrc = async (src) => {
const manifestRef = await findManifestForModelSrc(src).catch(() => null);
if (!manifestRef || !existsSync(manifestRef.manifestPath)) {
return null;
}
const manifest = await readJSONFile(manifestRef.manifestPath);
return normalizeViewerSettings(manifest?.viewerSettings);
};
const handleCreateShare = async (req, res) => {
const session = await getValidatedBimSession(req, res);
if (BIM_AUTH_REQUIRED && !session) {
@ -1973,9 +1988,8 @@ const handleCreateShare = async (req, res) => {
const name = typeof payload?.name === "string" && payload.name.trim()
? payload.name.trim().slice(0, 240)
: path.basename(src);
const viewerSettings = payload?.viewerSettings && typeof payload.viewerSettings === "object" && !Array.isArray(payload.viewerSettings)
? payload.viewerSettings
: null;
const viewerSettings = normalizeViewerSettings(payload?.viewerSettings)
|| await readViewerSettingsForModelSrc(settingsSrc || src);
const share = {
token,
access: "public-readonly",
@ -2058,6 +2072,8 @@ const handleGetShare = async (req, res, token) => {
projectId: share.projectId,
assetId: share.assetId
}).catch(() => null);
const viewerSettings = normalizeViewerSettings(share.viewerSettings)
|| await readViewerSettingsForModelSrc(share.settingsSrc || share.src);
sendJSON(res, 200, {
ok: true,
mode: authenticated ? "standard" : "guest",
@ -2077,7 +2093,7 @@ const handleGetShare = async (req, res, token) => {
projectId: share.projectId || null,
versionId: share.versionId || versionHistory?.currentVersionId || null,
selectedLod: share.selectedLod || null,
viewerSettings: share.viewerSettings || null,
viewerSettings,
versions: versionHistory?.versions || []
},
share: {