refactor(web): 拆 lib/api.ts 789→109 barrel + lib/api/ 8域文件(纯搬移零逻辑)
- lib/api/{core,auth,chat,sessions,personas,admin,adminChannels,adminSystem}.ts
- api.ts 改纯 barrel 显式 re-export(export type for types, isolatedModules); 导出名 77→77, 36处导入点零改动
- 代码行多重集比对一致(仅 request/limitQuery 各加一 export 供兄弟模块); 每文件≤500/函数≤80
- 前端 build 绿(165 modules)
This commit is contained in:
1 parent
153a9d6211
commit
4c3c98d5d4
9 files changed
+903
-779
No files matched your search
@@ -0,0 +1,152 @@
|
||||
import type {
|
||||
AdminChannelMessage,
|
||||
ChannelTestResult,
|
||||
KookFriendList,
|
||||
KookMessageTestResult,
|
||||
KookViewResponse,
|
||||
WeixinLoginQRResponse,
|
||||
WeixinLoginStatusResponse,
|
||||
} from "../types";
|
||||
import { request } from "./core";
|
||||
|
||||
/** Result of saving/deleting a channel account config (persisted to channels.json). */
|
||||
export interface ChannelConfigSaveResult {
|
||||
persisted: boolean;
|
||||
path: string;
|
||||
platform: string;
|
||||
accountId: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/channels/open — connects a registered channel adapter. */
|
||||
export function adminChannelOpen(name: string): Promise<{ name: string; connected: boolean }> {
|
||||
return request<{ name: string; connected: boolean }>("/admin/channels/open", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/channels/close — disconnects a registered channel adapter. */
|
||||
export function adminChannelClose(name: string): Promise<{ name: string; connected: boolean }> {
|
||||
return request<{ name: string; connected: boolean }>("/admin/channels/close", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/channels/test — structural identity test (actor × whitelist). */
|
||||
export function adminChannelTest(req: {
|
||||
platform: string;
|
||||
accountId: string;
|
||||
isGroup: boolean;
|
||||
}): Promise<ChannelTestResult> {
|
||||
return request<ChannelTestResult>("/admin/channels/test", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** GET /api/v1/admin/channels/messages?adapter=<composite> — one adapter config's
|
||||
* (platform:account) send/receive message log, newest first. */
|
||||
export function adminChannelMessages(adapter: string, limit?: number): Promise<AdminChannelMessage[]> {
|
||||
const q = new URLSearchParams({ adapter });
|
||||
if (limit && limit > 0) q.set("limit", String(limit));
|
||||
return request<AdminChannelMessage[]>(`/admin/channels/messages?${q.toString()}`);
|
||||
}
|
||||
/** GET /api/v1/admin/channels/messages — adapter overview log across all adapters. */
|
||||
export function adminChannelLogOverview(limit?: number): Promise<AdminChannelMessage[]> {
|
||||
const q = limit && limit > 0 ? `?limit=${limit}` : "";
|
||||
return request<AdminChannelMessage[]>(`/admin/channels/messages${q}`);
|
||||
}
|
||||
/** PUT /api/v1/admin/channels/{platform}/config — save an account config + hot-reload. */
|
||||
export function adminSaveChannelConfig(
|
||||
platform: string,
|
||||
req: {
|
||||
id?: string;
|
||||
token?: string;
|
||||
baseURL?: string;
|
||||
remoteURL?: string;
|
||||
listenAddr?: string;
|
||||
mode?: string;
|
||||
accessToken?: string;
|
||||
selfID?: string;
|
||||
config?: Record<string, unknown>;
|
||||
allowGroups?: string[];
|
||||
denyGroups?: string[];
|
||||
allowUsers?: string[];
|
||||
denyUsers?: string[];
|
||||
groupMsgPerMin?: number;
|
||||
msgPerMin?: number;
|
||||
maxMessages?: number;
|
||||
},
|
||||
): Promise<ChannelConfigSaveResult> {
|
||||
return request<ChannelConfigSaveResult>(`/admin/channels/${platform}/config`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** DELETE /api/v1/admin/channels/{platform}/config?id=… — delete an account + hot-reload. */
|
||||
export function adminDeleteChannelAccount(platform: string, id: string): Promise<ChannelConfigSaveResult> {
|
||||
return request<ChannelConfigSaveResult>(`/admin/channels/${platform}/config?id=${encodeURIComponent(id)}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
/** GET /api/v1/admin/channels/{platform}/view — one platform account's aggregated
|
||||
* panel data (friends / servers / channels / members / private chats), owner only. */
|
||||
export function adminChannelPlatformView(platform: string, accountId?: string): Promise<KookViewResponse> {
|
||||
const q = accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
||||
return request<KookViewResponse>(`/admin/channels/${encodeURIComponent(platform)}/view${q}`);
|
||||
}
|
||||
/** GET /api/v1/admin/channels/{platform}/friends?type= — friend/request/blocked list. */
|
||||
export function adminChannelPlatformFriends(
|
||||
platform: string,
|
||||
type: string,
|
||||
accountId?: string,
|
||||
): Promise<KookFriendList> {
|
||||
const q = new URLSearchParams();
|
||||
if (type) q.set("type", type);
|
||||
if (accountId) q.set("accountId", accountId);
|
||||
const qs = q.toString();
|
||||
return request<KookFriendList>(`/admin/channels/${encodeURIComponent(platform)}/friends${qs ? `?${qs}` : ""}`);
|
||||
}
|
||||
/** POST /api/v1/admin/channels/{platform}/friend/handle — accept/reject a friend request. */
|
||||
export function adminChannelFriendHandle(
|
||||
platform: string,
|
||||
id: number,
|
||||
accept: boolean,
|
||||
accountId?: string,
|
||||
): Promise<{ handled: boolean; id: number; accept: boolean }> {
|
||||
const q = accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
||||
return request<{ handled: boolean; id: number; accept: boolean }>(
|
||||
`/admin/channels/${encodeURIComponent(platform)}/friend/handle${q}`,
|
||||
{ method: "POST", body: JSON.stringify({ id, accept }) },
|
||||
);
|
||||
}
|
||||
/** POST /api/v1/admin/channels/{platform}/message/test — send one test message. */
|
||||
export function adminChannelMessageTest(
|
||||
platform: string,
|
||||
targetId: string,
|
||||
content: string,
|
||||
accountId?: string,
|
||||
): Promise<KookMessageTestResult> {
|
||||
const q = accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
||||
return request<KookMessageTestResult>(`/admin/channels/${encodeURIComponent(platform)}/message/test${q}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ targetId, content }),
|
||||
});
|
||||
}
|
||||
/** GET /api/v1/admin/channels/{platform}/login-qr — trigger/mint a weixin-iLink
|
||||
* scan-login QR code (owner only, audited). */
|
||||
export function adminWeixinLoginQR(
|
||||
platform: string,
|
||||
accountId?: string,
|
||||
): Promise<WeixinLoginQRResponse> {
|
||||
const q = accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
||||
return request<WeixinLoginQRResponse>(
|
||||
`/admin/channels/${encodeURIComponent(platform)}/login-qr${q}`,
|
||||
);
|
||||
}
|
||||
/** GET /api/v1/admin/channels/{platform}/login-status — poll a weixin-iLink scan
|
||||
* login. On confirmed the backend persists the token and hot-connects. */
|
||||
export function adminWeixinLoginStatus(
|
||||
platform: string,
|
||||
accountId?: string,
|
||||
): Promise<WeixinLoginStatusResponse> {
|
||||
const q = accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
||||
return request<WeixinLoginStatusResponse>(
|
||||
`/admin/channels/${encodeURIComponent(platform)}/login-status${q}`,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user