refactor(auth,config): split 2260-line login.ts into focused modules and normalize CorpConfig fields

This commit is contained in:
gitea committed 2026-09-30 00:04:28 +08:00
1 parent 2d744d283b
commit 2b220bc5d9
7 files changed
+1786 -1661

No files matched your search

+12 -10
View File
@@ -1,4 +1,10 @@
import { CorpConfig, GlobalConfig } from "./types.js";
import {
CorpConfig,
getCorpExpiresAt,
getCorpPhysicalId,
getCorpStaffId,
getCorpStaffName,
} from "./types.js";
import { saveGlobalConfig } from "./loader.js";
export interface CorpSummary {
@@ -35,11 +41,7 @@ export function resolveCorpConfig(
let corp = corps.find((item) => item.id === selectedCorpId);
// 2. 其次按企业物理 ID 匹配 (如 uzU7pcWfScck00)
if (!corp) {
corp = corps.find(
(item) =>
item.corpId === selectedCorpId ||
item.credentials.corpId === selectedCorpId
);
corp = corps.find((item) => getCorpPhysicalId(item) === selectedCorpId);
}
if (corp) return corp;
throw new Error(`未找到企业或身份标识为 [${selectedCorpId}] 的企业配置`);
@@ -160,14 +162,14 @@ export class CorpContext {
return {
id: corp.id,
name: corp.name,
corpId: corp.corpId || corp.credentials.corpId,
staffId: corp.credentials.staffId,
staffName: corp.staffName || corp.session?.staffName || undefined,
corpId: getCorpPhysicalId(corp),
staffId: getCorpStaffId(corp),
staffName: getCorpStaffName(corp),
source: corp.source || "manual",
accountId: corp.accountId,
baseUrl: corp.baseUrl,
current: corp.id === this.current?.id,
expiresAt: corp.auth?.expiresAt || (corp.session?.expTime ?? undefined),
expiresAt: getCorpExpiresAt(corp),
persistent: hasOpenApiKeys || hasAccountBinding,
};
});