Promote shared BIM links through launcher
This commit is contained in:
+60
-1
@@ -184,6 +184,7 @@ const AUTH_SESSION_API = "/api/auth/session";
|
||||
const SHARES_API = "/api/shares";
|
||||
const COMMENTS_API = "/api/comments";
|
||||
const UPLOAD_VERSIONS_API = "/api/uploads/versions";
|
||||
const SHARE_PROMOTION_TIMEOUT_MS = 4500;
|
||||
|
||||
const acceptByType = {
|
||||
xkt: ".xkt",
|
||||
@@ -620,6 +621,60 @@ const getShareTokenFromPath = () => {
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
};
|
||||
|
||||
const getCurrentReturnPath = () => `${window.location.pathname}${window.location.search || ""}${window.location.hash || ""}`;
|
||||
|
||||
const getShareTopLevelPromotionUrl = () => {
|
||||
const promoteUrl = startupSharePayload?.promoteUrl;
|
||||
return typeof promoteUrl === "string" && promoteUrl.trim() ? promoteUrl : "";
|
||||
};
|
||||
|
||||
const scheduleShareSessionPromotion = (shareToken) => {
|
||||
const silentPromoteUrl = startupSharePayload?.silentPromoteUrl;
|
||||
if (!shareToken || viewerMode !== "guest" || runtimeSessionInfo.authenticated || typeof silentPromoteUrl !== "string" || !silentPromoteUrl.trim()) {
|
||||
return;
|
||||
}
|
||||
let storageKey = "";
|
||||
try {
|
||||
storageKey = `bimdc-share-promote:${shareToken}`;
|
||||
if (sessionStorage.getItem(storageKey)) {
|
||||
return;
|
||||
}
|
||||
sessionStorage.setItem(storageKey, String(Date.now()));
|
||||
} catch (_) {
|
||||
storageKey = "";
|
||||
}
|
||||
|
||||
const iframe = document.createElement("iframe");
|
||||
iframe.title = "BIM share auth promotion";
|
||||
iframe.tabIndex = -1;
|
||||
iframe.setAttribute("aria-hidden", "true");
|
||||
iframe.style.cssText = "position:fixed;width:1px;height:1px;left:-10000px;top:-10000px;border:0;opacity:0;pointer-events:none;";
|
||||
|
||||
let done = false;
|
||||
let timeoutId = null;
|
||||
const cleanup = () => {
|
||||
window.removeEventListener("message", onMessage);
|
||||
if (timeoutId) window.clearTimeout(timeoutId);
|
||||
iframe.remove();
|
||||
};
|
||||
const onMessage = (event) => {
|
||||
if (event.origin !== window.location.origin) return;
|
||||
const payload = event.data || {};
|
||||
if (payload.type !== "nodedc:bim-share-promoted") return;
|
||||
done = true;
|
||||
cleanup();
|
||||
window.location.replace(payload.nextPath || getCurrentReturnPath());
|
||||
};
|
||||
|
||||
window.addEventListener("message", onMessage);
|
||||
timeoutId = window.setTimeout(() => {
|
||||
if (done) return;
|
||||
cleanup();
|
||||
}, SHARE_PROMOTION_TIMEOUT_MS);
|
||||
iframe.src = silentPromoteUrl;
|
||||
document.body.appendChild(iframe);
|
||||
};
|
||||
|
||||
const COMMENT_TARGET_ICON = `
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M6.5 4.75h11A3.25 3.25 0 0 1 20.75 8v6.25a3.25 3.25 0 0 1-3.25 3.25h-5.26l-5.29 3.82V17.5H6.5a3.25 3.25 0 0 1-3.25-3.25V8A3.25 3.25 0 0 1 6.5 4.75Z"></path>
|
||||
@@ -1794,6 +1849,9 @@ const initializeRuntimeMode = async () => {
|
||||
}
|
||||
|
||||
applyRuntimeMode();
|
||||
if (shareToken && viewerMode === "guest") {
|
||||
scheduleShareSessionPromotion(shareToken);
|
||||
}
|
||||
};
|
||||
|
||||
const getShareableModelPayload = () => {
|
||||
@@ -6525,7 +6583,8 @@ const loadProjectSnapshot = async (project) => {
|
||||
});
|
||||
|
||||
homeButton.addEventListener("click", () => {
|
||||
window.location.assign(getLauncherUrl());
|
||||
const sharePromoteUrl = getShareTokenFromPath() && isGuestMode() ? getShareTopLevelPromotionUrl() : "";
|
||||
window.location.assign(sharePromoteUrl || getLauncherUrl());
|
||||
});
|
||||
|
||||
if (saveProjectButton) {
|
||||
|
||||
+1
-1
@@ -292,7 +292,7 @@
|
||||
<div class="inspector-select-host" id="displayModeSelect"></div>
|
||||
</div>
|
||||
<div class="inspector-control-row inspector-control-row--half hidden" id="customDisplayColorRow">
|
||||
<div class="inspector-control-label">Цвет кастома</div>
|
||||
<div class="inspector-control-label">Цвет</div>
|
||||
<div class="inspector-color-host" id="customDisplayColorControl"></div>
|
||||
</div>
|
||||
<div class="inspector-control-row inspector-control-row--half" id="lightingModeControl">
|
||||
|
||||
Reference in New Issue
Block a user