This commit is contained in:
ZuoZuo 2026-04-25 12:39:36 +08:00
parent 3a3788c62b
commit b35509ebbc
4 changed files with 99 additions and 23 deletions

View File

@ -431,11 +431,17 @@ function getAllowedPages(roles) {
return pages; return pages;
} }
function getCurrentRoutePath() {
const pathWithoutSlash = window.location.pathname.replace(/\/+$/, "") || "/";
const pathWithoutIndex = pathWithoutSlash.replace(/\/index\.html$/, "") || "/";
return pathWithoutIndex.replace(/^\/h5(?=\/|$)/, "") || "/";
}
function applyPermissionRedirect() { function applyPermissionRedirect() {
const roles = getIdentityRoles(state.identityInfo); const roles = getIdentityRoles(state.identityInfo);
const primaryRole = getPrimaryRole(roles); const primaryRole = getPrimaryRole(roles);
const allowedPages = getAllowedPages(roles); const allowedPages = getAllowedPages(roles);
const currentPath = window.location.pathname.replace(/\/$/, "") || "/"; const currentPath = getCurrentRoutePath();
if (!allowedPages.has(currentPath)) { if (!allowedPages.has(currentPath)) {
navigateTo(roleDefaultPages[primaryRole] || "/apply"); navigateTo(roleDefaultPages[primaryRole] || "/apply");

View File

@ -153,7 +153,7 @@ const text = {
}); });
let headers = { let headers = {
authorization: "Bearer undefined", authorization: "",
"req-app-intel": "version=1.0.0;build=1;model=SM-G9550;sysVersion=9;channel=Google", "req-app-intel": "version=1.0.0;build=1;model=SM-G9550;sysVersion=9;channel=Google",
"req-client": "Android", "req-client": "Android",
"req-imei": "8fa54d728ab449e04f9292329ed44bda", "req-imei": "8fa54d728ab449e04f9292329ed44bda",
@ -165,6 +165,7 @@ let headers = {
}; };
export const lang = resolveLanguage(); export const lang = resolveLanguage();
let appConnectionPromise = null;
export function t(key) { export function t(key) {
return text[lang]?.[key] || text.en[key] || key; return text[lang]?.[key] || text.en[key] || key;
@ -206,21 +207,21 @@ function parseAppHeaders(raw) {
const appIntel = splitHeaderPairs(data["Req-App-Intel"]); const appIntel = splitHeaderPairs(data["Req-App-Intel"]);
const sysOrigin = splitHeaderPairs(data["Req-Sys-Origin"]); const sysOrigin = splitHeaderPairs(data["Req-Sys-Origin"]);
return { return {
authorization: data.Authorization, authorization: data.Authorization || data.authorization,
reqLang: data["Req-Lang"], reqLang: data["Req-Lang"] || data.reqLang || data.lang,
appVersion: appIntel.version, appVersion: appIntel.version || data["App-Version"] || data.appVersion,
buildVersion: appIntel.build, buildVersion: appIntel.build || data["Build-Version"] || data.buildVersion,
channel: appIntel.channel, channel: appIntel.channel || data["App-Channel"] || data.appChannel || data.channel,
reqImei: appIntel["Req-Imei"], reqImei: data["Req-Imei"] || data.reqImei || appIntel["Req-Imei"],
origin: sysOrigin.origin, origin: sysOrigin.origin || data["Sys-Origin"] || data.sysOrigin,
child: sysOrigin.child child: sysOrigin.originChild || sysOrigin.child || data["Sys-Origin-Child"] || data.sysOriginChild
}; };
} }
export function setHeadersFromApp(rawOrObject) { export function setHeadersFromApp(rawOrObject) {
const data = typeof rawOrObject === "string" ? parseAppHeaders(rawOrObject) : rawOrObject || {}; const data = typeof rawOrObject === "string" ? parseAppHeaders(rawOrObject) : rawOrObject || {};
const next = {}; 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.reqLang) next["req-lang"] = data.reqLang;
if (data.appVersion || data.buildVersion || data.channel) { if (data.appVersion || data.buildVersion || data.channel) {
next["req-app-intel"] = [ next["req-app-intel"] = [
@ -234,18 +235,87 @@ export function setHeadersFromApp(rawOrObject) {
headers = { ...headers, ...next }; 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() { export async function connectToApp() {
window.renderData = (raw) => raw && setHeadersFromApp(raw); if (!appConnectionPromise) {
window.getIosAccessOriginParam = window.renderData; appConnectionPromise = requestAccessOrigin()
if (window.app && typeof window.app.getAccessOrigin === "function") { .then((raw) => {
const raw = window.app.getAccessOrigin(); if (raw) setHeadersFromApp(raw);
if (raw) setHeadersFromApp(raw); return { success: true, environment: isAppEnvironment() ? "app" : "browser" };
return; })
.finally(() => {
appConnectionPromise = null;
});
} }
if (window.FlutterApp && typeof window.FlutterApp.postMessage === "function") {
window.FlutterApp.postMessage("requestAccessOrigin"); return appConnectionPromise;
}
setHeadersFromApp({ reqLang: lang, authorization: "" });
} }
export async function request(method, path, body) { export async function request(method, path, body) {

View File

@ -23,6 +23,6 @@
<div class="subtle" id="empty" data-i18n="no_users_found">No users found</div> <div class="subtle" id="empty" data-i18n="no_users_found">No users found</div>
</section> </section>
</main> </main>
<script type="module" src="./invite.js"></script> <script type="module" src="./invite.js?v=auth-bridge-1"></script>
</body> </body>
</html> </html>

View File

@ -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 = { const state = {
query: "", query: "",