Files
monkey-ai-web/src/helpers/miniProgram.js
T
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

57 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// WeyAi 微信小程序的 web-view 里打开登录页时(WeyAi 仓库 docs/fork/16 第 5.2 节 MP-M1):
// web-view 只能打开登记过的业务域名,第三方登录要跳到 GitHub、OIDC 等外部域名,会被拦下;
// passkey 依赖的 WebAuthn 在 web-view 里也用不了。所以只留站内能完成的方式:
// 账号密码、公众号验证码、2FA、首次改密码。
/**
* 是否在小程序 web-view 里。JSSDK 注入的 `__wxjs_environment` 最准,但要等 WeixinJSBridgeReady;
* 页面刚加载时它可能还没有,所以再用 UA 里的 `miniProgram` 兜底(安卓和 iOS 的 web-view 都带)。
*/
export function isMiniProgramWebView(
win = typeof window === 'undefined' ? undefined : window,
) {
if (!win) return false;
if (win.__wxjs_environment === 'miniprogram') return true;
const ua = (win.navigator?.userAgent || '').toLowerCase();
return ua.includes('miniprogram');
}
/** 要跳到外部域名、或依赖 WebAuthn 的登录方式开关。 */
const EXTERNAL_LOGIN_FLAGS = [
'github_oauth',
'discord_oauth',
'oidc_enabled',
'linuxdo_oauth',
'telegram_oauth',
'wechat_open_oauth',
'passkey_login',
];
/**
* 小程序里不出现的付费页面。iOS 小程序按微信规则不能售卖虚拟商品,充值和开票都回到网页完成
* (WeyAi 仓库 docs/fork/16)。
*/
const MINI_PROGRAM_PAYMENT_PATHS = [
'/recharge',
'/topup',
'/user-center/topup',
'/user-center/invoice',
'/console/topup',
'/org/recharge',
];
/** 这个地址是不是小程序里不出现的付费页面(含其下的子路径)。 */
export function isMiniProgramPaymentPath(pathname) {
const path = (pathname || '').replace(/\/+$/, '');
return MINI_PROGRAM_PAYMENT_PATHS.some(
(prefix) => path === prefix || path.startsWith(`${prefix}/`),
);
}
/** 小程序里用的站点状态:关掉上面这些开关,其他原样保留(包括 Turnstile)。 */
export function withMiniProgramLogins(status) {
const next = { ...status };
for (const flag of EXTERNAL_LOGIN_FLAGS) next[flag] = false;
return next;
}