feat(auth): support OpenAPI persistent credentials, auto-refresh, and Web login link generation (v0.8.10)
This commit is contained in:
1 parent
1d825269f4
commit
96c5a3f242
27 files changed
+2994
-583
No files matched your search
+17
-11
@@ -41,40 +41,46 @@ export function printJson(data: unknown, options: OutputOptions = {}): string {
|
||||
return json;
|
||||
}
|
||||
|
||||
export function formatSourceLabel(source?: string): string {
|
||||
export function formatSourceLabel(source?: string, persistentOpenApi?: boolean): string {
|
||||
const suffix = persistentOpenApi && source !== "openapi" ? " + OpenAPI 持久化密钥" : "";
|
||||
switch (source) {
|
||||
case "openapi":
|
||||
return "开放平台持久化密钥 (OpenAPI AppKey)";
|
||||
case "assist":
|
||||
return "官方协助/代客平台 (Assist Platform)";
|
||||
return `官方协助/代客平台 (Assist Platform)${suffix}`;
|
||||
case "account":
|
||||
return "统一认证中心 (IDP 账密/短信)";
|
||||
return `统一认证中心 (IDP 账密/短信)${suffix}`;
|
||||
case "browser":
|
||||
return "浏览器会话同步 (WebBridge)";
|
||||
return `浏览器会话同步 (WebBridge)${suffix}`;
|
||||
case "link":
|
||||
return "协助/免密链接导入 (Assistance Link)";
|
||||
return `协助/免密链接导入 (Assistance Link)${suffix}`;
|
||||
case "curl":
|
||||
case "f12":
|
||||
return "cURL 抓包导入 (cURL/F12)";
|
||||
return `cURL 抓包导入 (cURL/F12)${suffix}`;
|
||||
case "manual":
|
||||
return "手动配置";
|
||||
return `手动配置${suffix}`;
|
||||
default:
|
||||
return source || "未知来源";
|
||||
return (source || "未知来源") + suffix;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatExpiresAt(expiresAt?: number | null): string {
|
||||
export function formatExpiresAt(expiresAt?: number | null, persistent?: boolean): string {
|
||||
if (!expiresAt || expiresAt <= 0) return "长期有效 / 服务端未显式限制";
|
||||
const diffMs = expiresAt - Date.now();
|
||||
const dateStr = new Date(expiresAt).toLocaleString("zh-CN", { hour12: false });
|
||||
if (diffMs <= 0) {
|
||||
if (persistent) {
|
||||
return `${dateStr} (🔄 持久化密钥自动续期)`;
|
||||
}
|
||||
return `${dateStr} (⚠️ 已过期)`;
|
||||
}
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
if (diffMins < 60) {
|
||||
return `${dateStr} (约剩余 ${diffMins} 分钟)`;
|
||||
return `${dateStr} (约剩余 ${diffMins} 分钟${persistent ? ",支持自动续期" : ""})`;
|
||||
}
|
||||
const diffHours = (diffMs / 3600000).toFixed(1);
|
||||
if (Number(diffHours) < 24) {
|
||||
return `${dateStr} (约剩余 ${diffHours} 小时)`;
|
||||
return `${dateStr} (约剩余 ${diffHours} 小时${persistent ? ",支持自动续期" : ""})`;
|
||||
}
|
||||
const diffDays = Math.floor(diffMs / 86400000);
|
||||
return `${dateStr} (约剩余 ${diffDays} 天)`;
|
||||
|
||||
Reference in new issue
Block a user