refactor(corps): normalize credential categories and format workflow history logs
This commit is contained in:
1 parent
f91a80f9dd
commit
0499ccb2cc
9 files changed
+161
-49
No files matched your search
+58
-18
@@ -42,48 +42,88 @@ export function printJson(data: unknown, options: OutputOptions = {}): string {
|
||||
}
|
||||
|
||||
export function formatSourceLabel(source?: string, persistentOpenApi?: boolean): string {
|
||||
const suffix = persistentOpenApi && source !== "openapi" ? " + OpenAPI 持久化密钥" : "";
|
||||
if (persistentOpenApi || source === "openapi") {
|
||||
return "企业开放接口 (OpenAPI 密钥)";
|
||||
}
|
||||
switch (source) {
|
||||
case "openapi":
|
||||
return "开放平台持久化密钥 (OpenAPI AppKey)";
|
||||
case "assist":
|
||||
return `官方协助/代客平台 (Assist Platform)${suffix}`;
|
||||
case "account":
|
||||
return `统一认证中心 (IDP 账密/短信)${suffix}`;
|
||||
case "browser":
|
||||
return `浏览器会话同步 (WebBridge)${suffix}`;
|
||||
return "个人账号凭证 (手机号)";
|
||||
case "assist":
|
||||
case "link":
|
||||
return `协助/免密链接导入 (Assistance Link)${suffix}`;
|
||||
return "合思协助平台授权链接 (协助链接)";
|
||||
case "browser":
|
||||
case "curl":
|
||||
case "f12":
|
||||
return `cURL 抓包导入 (cURL/F12)${suffix}`;
|
||||
return "网页临时抓包凭证 (Cookie)";
|
||||
case "manual":
|
||||
return `手动配置${suffix}`;
|
||||
return "手动配置";
|
||||
default:
|
||||
return (source || "未知来源") + suffix;
|
||||
return source ? `其他 (${source})` : "未知来源";
|
||||
}
|
||||
}
|
||||
|
||||
export function formatExpiresAt(expiresAt?: number | null, persistent?: boolean): string {
|
||||
if (!expiresAt || expiresAt <= 0) return "长期有效 / 服务端未显式限制";
|
||||
export function formatExpiresAt(
|
||||
expiresAt?: number | null,
|
||||
persistent?: boolean,
|
||||
source?: string
|
||||
): string {
|
||||
if (!expiresAt || expiresAt <= 0) {
|
||||
if (source === "openapi") {
|
||||
return "长期有效 (OpenAPI 密钥)";
|
||||
}
|
||||
return "长期有效 / 服务端未显式限制";
|
||||
}
|
||||
const diffMs = expiresAt - Date.now();
|
||||
const dateStr = new Date(expiresAt).toLocaleString("zh-CN", { hour12: false });
|
||||
if (diffMs <= 0) {
|
||||
if (persistent) {
|
||||
return `${dateStr} (🔄 持久化密钥自动续期)`;
|
||||
if (source === "account") {
|
||||
return `${dateStr} (🔄 随主账号自动换票)`;
|
||||
}
|
||||
if (source === "openapi") {
|
||||
return `${dateStr} (🔄 OpenAPI 密钥自动续期)`;
|
||||
}
|
||||
return `${dateStr} (🔄 自动续期)`;
|
||||
}
|
||||
if (source === "link" || source === "assist") {
|
||||
return `${dateStr} (⚠️ 协助授权已失效)`;
|
||||
}
|
||||
if (source === "curl" || source === "browser" || source === "f12") {
|
||||
return `${dateStr} (⚠️ Cookie 已失效)`;
|
||||
}
|
||||
return `${dateStr} (⚠️ 已过期)`;
|
||||
}
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
if (diffMins < 60) {
|
||||
return `${dateStr} (约剩余 ${diffMins} 分钟${persistent ? ",支持自动续期" : ""})`;
|
||||
const renewSuffix = persistent
|
||||
? source === "account"
|
||||
? ",支持主账号自动换票"
|
||||
: source === "openapi"
|
||||
? ",支持 OpenAPI 密钥自动续期"
|
||||
: ",支持自动续期"
|
||||
: "";
|
||||
return `${dateStr} (约剩余 ${diffMins} 分钟${renewSuffix})`;
|
||||
}
|
||||
const diffHours = (diffMs / 3600000).toFixed(1);
|
||||
if (Number(diffHours) < 24) {
|
||||
return `${dateStr} (约剩余 ${diffHours} 小时${persistent ? ",支持自动续期" : ""})`;
|
||||
const renewSuffix = persistent
|
||||
? source === "account"
|
||||
? ",支持主账号自动换票"
|
||||
: source === "openapi"
|
||||
? ",支持 OpenAPI 密钥自动续期"
|
||||
: ",支持自动续期"
|
||||
: "";
|
||||
return `${dateStr} (约剩余 ${diffHours} 小时${renewSuffix})`;
|
||||
}
|
||||
const diffDays = Math.floor(diffMs / 86400000);
|
||||
return `${dateStr} (约剩余 ${diffDays} 天)`;
|
||||
const renewSuffix = persistent
|
||||
? source === "account"
|
||||
? ",支持主账号自动换票"
|
||||
: source === "openapi"
|
||||
? ",支持 OpenAPI 密钥自动续期"
|
||||
: ""
|
||||
: "";
|
||||
return `${dateStr} (约剩余 ${diffDays} 天${renewSuffix})`;
|
||||
}
|
||||
|
||||
export function printKeyValue(pairs: Record<string, unknown>): string {
|
||||
|
||||
Reference in new issue
Block a user