fix: open install guide deeplinks via external app gateway

This commit is contained in:
3252a8
2026-05-23 23:07:42 +03:00
parent 0eeabc7b3a
commit 5918a6cc71
9 changed files with 378 additions and 24 deletions
+61
View File
@@ -0,0 +1,61 @@
export function hasControlChars(value) {
return Array.from(String(value || "")).some((char) => {
const code = char.charCodeAt(0);
return code <= 31 || code === 127;
});
}
export function isUnsafeAppUrl(value) {
return (
!String(value || "").trim() ||
hasControlChars(value) ||
/^(?:javascript|data|vbscript):/i.test(String(value || "").trim())
);
}
export function isHttpUrl(value) {
return /^https?:\/\//i.test(String(value || "").trim());
}
export function isExternalAppLaunchPath(pathname) {
const normalized = String(pathname || "")
.trim()
.replace(/\/+$/, "");
return normalized === "/open-app";
}
export function readExternalAppLaunchTarget(locationRef = null) {
const ref = locationRef || (typeof window === "undefined" ? null : window.location);
if (!ref?.hash) return "";
const target = String(new URLSearchParams(ref.hash.replace(/^#/, "")).get("url") || "").trim();
if (isUnsafeAppUrl(target) || isHttpUrl(target)) return "";
return target;
}
export function buildExternalAppLaunchUrl(value, locationRef = null) {
const target = String(value || "").trim();
if (isUnsafeAppUrl(target) || isHttpUrl(target)) return "";
const ref = locationRef || (typeof window === "undefined" ? null : window.location);
if (!ref?.href) return "";
const url = new URL("/open-app", ref.href);
url.hash = new URLSearchParams({ url: target }).toString();
return url.href;
}
export function openUrlWithHiddenAnchor(url) {
try {
const anchor = document.createElement("a");
anchor.href = url;
anchor.target = "_self";
anchor.rel = "noreferrer";
anchor.style.display = "none";
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
} catch {
window.location.assign(url);
}
}