File size: 1,140 Bytes
e81f4e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { RuntimeConfig } from "../config";

// Resin 反向代理 URL 重写: https://host/path -> <prefix>/host/path。
// 未配置 resin_proxy 或非 https URL 时原样返回。
export function resinProxyUrl(cfg: RuntimeConfig, url: string): string {
	const prefix = String(cfg?.resin_proxy || "")
		.trim()
		.replace(/\/$/, "");
	if (!prefix || typeof url !== "string" || !url.startsWith("https://"))
		return url;
	return `${prefix}/${url.slice("https://".length)}`;
}

// 登录账号路径前缀 (/u/{auth_user});未配置 auth_user 时返回空串。
export function accountPrefix(cfg: RuntimeConfig): string {
	const user = String(cfg?.auth_user || "").trim();
	return user ? `/u/${user}` : "";
}

// Gemini app 页面 URL,用于抓取 page token 与刷新 BL(经 resin_proxy 重写)。
export function geminiAppUrl(cfg: RuntimeConfig): string {
	const prefix = accountPrefix(cfg);
	const raw = `https://gemini.google.com${prefix}/app`;
	if (cfg?.resin_proxy) return resinProxyUrl(cfg, raw);
	const origin = (cfg?.gemini_origin || "https://gemini.google.com").replace(
		/\/$/,
		"",
	);
	return `${origin}${prefix}/app`;
}