feat(auth): 完善多账号与企业分层管理模型,全面支持 F12/cURL 临时凭证导入与一键保活

This commit is contained in:
gitea committed 2026-08-27 10:49:20 +08:00
1 parent 255c7aee8d
commit 3d549e2e2f
8 files changed
+749 -155

No files matched your search

+35 -5
View File
@@ -1,15 +1,30 @@
import { CorpConfig } from "./types";
import { CorpConfig } from "./types.js";
export interface CorpSummary {
id: string;
name: string;
source?: string;
accountId?: string;
staffId: string;
baseUrl?: string;
current: boolean;
}
export class CorpContext {
private current: CorpConfig | null = null;
private corps: Map<string, CorpConfig> = new Map();
constructor(corps: CorpConfig[]) {
constructor(corps: CorpConfig[] = []) {
this.reload(corps);
}
reload(corps: CorpConfig[]): void {
this.corps.clear();
for (const corp of corps) {
this.corps.set(corp.id, corp);
}
if (corps.length > 0) {
this.current = corps[0];
if (this.corps.size > 0 && (!this.current || !this.corps.has(this.current.id))) {
this.current = Array.from(this.corps.values())[0];
}
}
@@ -17,6 +32,17 @@ export class CorpContext {
return this.current;
}
getCorp(corpId: string): CorpConfig | undefined {
return this.corps.get(corpId);
}
upsertCorp(corp: CorpConfig, setCurrent: boolean = false): void {
this.corps.set(corp.id, corp);
if (setCurrent || !this.current) {
this.current = corp;
}
}
switchCorp(corpId: string): boolean {
const corp = this.corps.get(corpId);
if (!corp) return false;
@@ -24,10 +50,14 @@ export class CorpContext {
return true;
}
listCorps(): Array<{ id: string; name: string; current: boolean }> {
listCorps(): CorpSummary[] {
return Array.from(this.corps.values()).map((corp) => ({
id: corp.id,
name: corp.name,
source: corp.source || "manual",
accountId: corp.accountId,
staffId: corp.credentials.staffId,
baseUrl: corp.baseUrl,
current: corp.id === this.current?.id,
}));
}