Fix authenticated BIM share promotion
This commit is contained in:
+34
-5
@@ -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_AUTH_GUEST_PARAM = "ndc_bim_guest";
|
||||
const SHARE_PROMOTION_TIMEOUT_MS = 4500;
|
||||
|
||||
const acceptByType = {
|
||||
@@ -624,13 +625,39 @@ const getShareTokenFromPath = () => {
|
||||
const getCurrentReturnPath = () => `${window.location.pathname}${window.location.search || ""}${window.location.hash || ""}`;
|
||||
|
||||
const getShareTopLevelPromotionUrl = () => {
|
||||
const promoteUrl = startupSharePayload?.promoteUrl;
|
||||
const promoteUrl = startupSharePayload?.optionalPromoteUrl || startupSharePayload?.promoteUrl;
|
||||
return typeof promoteUrl === "string" && promoteUrl.trim() ? promoteUrl : "";
|
||||
};
|
||||
|
||||
const hasShareGuestAuthMarker = () => {
|
||||
try {
|
||||
return new URLSearchParams(window.location.search || "").get(SHARE_AUTH_GUEST_PARAM) === "1";
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const clearShareGuestAuthMarker = () => {
|
||||
if (!hasShareGuestAuthMarker()) return;
|
||||
try {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete(SHARE_AUTH_GUEST_PARAM);
|
||||
window.history.replaceState(window.history.state, "", `${url.pathname}${url.search}${url.hash}`);
|
||||
} catch (_) {
|
||||
// keep current URL if the History API is unavailable
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleShareSessionPromotion = (shareToken) => {
|
||||
const silentPromoteUrl = startupSharePayload?.silentPromoteUrl;
|
||||
if (!shareToken || viewerMode !== "guest" || runtimeSessionInfo.authenticated || typeof silentPromoteUrl !== "string" || !silentPromoteUrl.trim()) {
|
||||
if (
|
||||
!shareToken ||
|
||||
hasShareGuestAuthMarker() ||
|
||||
viewerMode !== "guest" ||
|
||||
runtimeSessionInfo.authenticated ||
|
||||
typeof silentPromoteUrl !== "string" ||
|
||||
!silentPromoteUrl.trim()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let storageKey = "";
|
||||
@@ -1810,6 +1837,7 @@ const applyRuntimeMode = () => {
|
||||
|
||||
const initializeRuntimeMode = async () => {
|
||||
const shareToken = getShareTokenFromPath();
|
||||
const shareGuestAuthMarker = hasShareGuestAuthMarker();
|
||||
if (shareToken) {
|
||||
viewerMode = "guest";
|
||||
inspectorCollapsed = true;
|
||||
@@ -1849,7 +1877,8 @@ const initializeRuntimeMode = async () => {
|
||||
}
|
||||
|
||||
applyRuntimeMode();
|
||||
if (shareToken && viewerMode === "guest") {
|
||||
clearShareGuestAuthMarker();
|
||||
if (shareToken && viewerMode === "guest" && !shareGuestAuthMarker) {
|
||||
scheduleShareSessionPromotion(shareToken);
|
||||
}
|
||||
};
|
||||
@@ -5182,13 +5211,13 @@ const applyViewerState = (state) => {
|
||||
};
|
||||
|
||||
const initViewer = async () => {
|
||||
// remove preload hidden style ASAP
|
||||
await initializeRuntimeMode();
|
||||
|
||||
const preloadHidden = document.getElementById("preload-hidden");
|
||||
if (preloadHidden) {
|
||||
preloadHidden.remove();
|
||||
}
|
||||
document.body.style.opacity = "1";
|
||||
await initializeRuntimeMode();
|
||||
|
||||
const sdk = await import(SDK_URL);
|
||||
sdkRef = sdk;
|
||||
|
||||
Reference in New Issue
Block a user