1
This commit is contained in:
parent
3a3788c62b
commit
b35509ebbc
@ -431,11 +431,17 @@ function getAllowedPages(roles) {
|
||||
return pages;
|
||||
}
|
||||
|
||||
function getCurrentRoutePath() {
|
||||
const pathWithoutSlash = window.location.pathname.replace(/\/+$/, "") || "/";
|
||||
const pathWithoutIndex = pathWithoutSlash.replace(/\/index\.html$/, "") || "/";
|
||||
return pathWithoutIndex.replace(/^\/h5(?=\/|$)/, "") || "/";
|
||||
}
|
||||
|
||||
function applyPermissionRedirect() {
|
||||
const roles = getIdentityRoles(state.identityInfo);
|
||||
const primaryRole = getPrimaryRole(roles);
|
||||
const allowedPages = getAllowedPages(roles);
|
||||
const currentPath = window.location.pathname.replace(/\/$/, "") || "/";
|
||||
const currentPath = getCurrentRoutePath();
|
||||
|
||||
if (!allowedPages.has(currentPath)) {
|
||||
navigateTo(roleDefaultPages[primaryRole] || "/apply");
|
||||
|
||||
@ -153,7 +153,7 @@ const text = {
|
||||
});
|
||||
|
||||
let headers = {
|
||||
authorization: "Bearer undefined",
|
||||
authorization: "",
|
||||
"req-app-intel": "version=1.0.0;build=1;model=SM-G9550;sysVersion=9;channel=Google",
|
||||
"req-client": "Android",
|
||||
"req-imei": "8fa54d728ab449e04f9292329ed44bda",
|
||||
@ -165,6 +165,7 @@ let headers = {
|
||||
};
|
||||
|
||||
export const lang = resolveLanguage();
|
||||
let appConnectionPromise = null;
|
||||
|
||||
export function t(key) {
|
||||
return text[lang]?.[key] || text.en[key] || key;
|
||||
@ -206,21 +207,21 @@ function parseAppHeaders(raw) {
|
||||
const appIntel = splitHeaderPairs(data["Req-App-Intel"]);
|
||||
const sysOrigin = splitHeaderPairs(data["Req-Sys-Origin"]);
|
||||
return {
|
||||
authorization: data.Authorization,
|
||||
reqLang: data["Req-Lang"],
|
||||
appVersion: appIntel.version,
|
||||
buildVersion: appIntel.build,
|
||||
channel: appIntel.channel,
|
||||
reqImei: appIntel["Req-Imei"],
|
||||
origin: sysOrigin.origin,
|
||||
child: sysOrigin.child
|
||||
authorization: data.Authorization || data.authorization,
|
||||
reqLang: data["Req-Lang"] || data.reqLang || data.lang,
|
||||
appVersion: appIntel.version || data["App-Version"] || data.appVersion,
|
||||
buildVersion: appIntel.build || data["Build-Version"] || data.buildVersion,
|
||||
channel: appIntel.channel || data["App-Channel"] || data.appChannel || data.channel,
|
||||
reqImei: data["Req-Imei"] || data.reqImei || appIntel["Req-Imei"],
|
||||
origin: sysOrigin.origin || data["Sys-Origin"] || data.sysOrigin,
|
||||
child: sysOrigin.originChild || sysOrigin.child || data["Sys-Origin-Child"] || data.sysOriginChild
|
||||
};
|
||||
}
|
||||
|
||||
export function setHeadersFromApp(rawOrObject) {
|
||||
const data = typeof rawOrObject === "string" ? parseAppHeaders(rawOrObject) : rawOrObject || {};
|
||||
const next = {};
|
||||
if (data.authorization) next.authorization = data.authorization;
|
||||
if (Object.prototype.hasOwnProperty.call(data, "authorization")) next.authorization = data.authorization || "";
|
||||
if (data.reqLang) next["req-lang"] = data.reqLang;
|
||||
if (data.appVersion || data.buildVersion || data.channel) {
|
||||
next["req-app-intel"] = [
|
||||
@ -234,18 +235,87 @@ export function setHeadersFromApp(rawOrObject) {
|
||||
headers = { ...headers, ...next };
|
||||
}
|
||||
|
||||
function isAppEnvironment() {
|
||||
return Boolean(window.app || window.webkit || window.FlutterPageControl || window.FlutterApp);
|
||||
}
|
||||
|
||||
function requestAccessOrigin() {
|
||||
return new Promise((resolve) => {
|
||||
let settled = false;
|
||||
let timeoutId = null;
|
||||
const finish = (raw) => {
|
||||
if (settled) {
|
||||
if (raw) setHeadersFromApp(raw);
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
if (timeoutId) window.clearTimeout(timeoutId);
|
||||
resolve(raw || null);
|
||||
};
|
||||
|
||||
window.renderData = finish;
|
||||
window.getIosAccessOriginParam = finish;
|
||||
|
||||
if (!isAppEnvironment()) {
|
||||
setHeadersFromApp({
|
||||
authorization: "",
|
||||
reqLang: lang,
|
||||
appVersion: "1.0.0",
|
||||
buildVersion: "1",
|
||||
channel: "Web",
|
||||
reqImei: "H5-STATIC",
|
||||
origin: "LIKEI",
|
||||
child: "LIKEI"
|
||||
});
|
||||
finish(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const requestFromFlutter = () => {
|
||||
if (window.FlutterApp && typeof window.FlutterApp.postMessage === "function") {
|
||||
window.FlutterApp.postMessage("requestAccessOrigin");
|
||||
}
|
||||
};
|
||||
|
||||
if (window.app && typeof window.app.getAccessOrigin === "function") {
|
||||
finish(window.app.getAccessOrigin());
|
||||
return;
|
||||
}
|
||||
|
||||
requestFromFlutter();
|
||||
timeoutId = window.setTimeout(() => finish(null), 12000);
|
||||
|
||||
let attempt = 0;
|
||||
const poll = () => {
|
||||
attempt += 1;
|
||||
if (window.app && typeof window.app.getAccessOrigin === "function") {
|
||||
finish(window.app.getAccessOrigin());
|
||||
return;
|
||||
}
|
||||
if (attempt < 50) {
|
||||
window.setTimeout(poll, 100);
|
||||
return;
|
||||
}
|
||||
requestFromFlutter();
|
||||
};
|
||||
|
||||
poll();
|
||||
});
|
||||
}
|
||||
|
||||
export async function connectToApp() {
|
||||
window.renderData = (raw) => raw && setHeadersFromApp(raw);
|
||||
window.getIosAccessOriginParam = window.renderData;
|
||||
if (window.app && typeof window.app.getAccessOrigin === "function") {
|
||||
const raw = window.app.getAccessOrigin();
|
||||
if (raw) setHeadersFromApp(raw);
|
||||
return;
|
||||
if (!appConnectionPromise) {
|
||||
appConnectionPromise = requestAccessOrigin()
|
||||
.then((raw) => {
|
||||
if (raw) setHeadersFromApp(raw);
|
||||
return { success: true, environment: isAppEnvironment() ? "app" : "browser" };
|
||||
})
|
||||
.finally(() => {
|
||||
appConnectionPromise = null;
|
||||
});
|
||||
}
|
||||
if (window.FlutterApp && typeof window.FlutterApp.postMessage === "function") {
|
||||
window.FlutterApp.postMessage("requestAccessOrigin");
|
||||
}
|
||||
setHeadersFromApp({ reqLang: lang, authorization: "" });
|
||||
|
||||
return appConnectionPromise;
|
||||
}
|
||||
|
||||
export async function request(method, path, body) {
|
||||
|
||||
@ -23,6 +23,6 @@
|
||||
<div class="subtle" id="empty" data-i18n="no_users_found">No users found</div>
|
||||
</section>
|
||||
</main>
|
||||
<script type="module" src="./invite.js"></script>
|
||||
<script type="module" src="./invite.js?v=auth-bridge-1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { applyLang, avatarError, bindHeader, connectToApp, get, post, t, toast } from "../bd-static/shared.js";
|
||||
import { applyLang, avatarError, bindHeader, connectToApp, get, post, t, toast } from "../bd-static/shared.js?v=auth-bridge-1";
|
||||
|
||||
const state = {
|
||||
query: "",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user