feat: implement get cookies and CSRF and credentials

This commit is contained in:
H3CoF6 committed 2026-05-09 05:17:18 +08:00
1 parent 8b313fe088
commit c8dd520d65
5 files changed
+95 -6

No files matched your search

+30 -6
View File
@@ -413,18 +413,42 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
// --- Credentials ---
h.registerAction('get_cookies', async () => {
return okResponse({ cookies: '' });
h.registerAction('get_cookies', async (params) => {
const domain = asString(params.domain) || 'qun.qq.com';
if (!ctx.getCookiesStr) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
try {
const cookies = await ctx.getCookiesStr(domain);
return okResponse({ cookies });
} catch (e) {
return failedResponse(RETCODE.ACTION_FAILED, String(e));
}
});
h.registerAction('get_csrf_token', async () => {
return okResponse({ token: 0 });
if (!ctx.getCsrfToken) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
try {
const token = await ctx.getCsrfToken();
return okResponse({ token });
} catch (e) {
return failedResponse(RETCODE.ACTION_FAILED, String(e));
}
});
h.registerAction('get_credentials', async () => {
return okResponse({ cookies: '', csrf_token: 0 });
});
h.registerAction('get_credentials', async (params) => {
const domain = asString(params.domain) || 'qun.qq.com';
if (!ctx.getCredentials) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
try {
const creds = await ctx.getCredentials(domain);
return okResponse(creds);
} catch (e) {
return failedResponse(RETCODE.ACTION_FAILED, String(e));
}
});
// --- Utility ---
h.registerAction('set_restart', async () => {
+3
View File
@@ -102,6 +102,9 @@ export interface ApiActionContext {
getGroupEssenceAll?: (groupId: number) => Promise<GroupEssenceMsgRet[]>;
sendGroupNotice?: (groupId: number, content: string, options?: any) => Promise<any>;
getGroupNotice?: (groupId: number) => Promise<any[]>;
getCookiesStr?: (domain: string) => Promise<string>;
getCsrfToken?: () => Promise<number>;
getCredentials?: (domain: string) => Promise<{ cookies: string; token: number; csrf_token: number }>;
}
type ActionHandler = (params: JsonObject) => Promise<import('./types').ApiResponse>;
@@ -132,6 +132,9 @@ export function buildApiContext(ref: InstanceRef): ApiActionContext {
getGroupEssenceAll: (groupId: number) => bridge.getGroupEssenceAll(groupId),
sendGroupNotice: (groupId: number, content: string, options?: any) => bridge.sendGroupNotice(groupId, content, options),
getGroupNotice: (groupId: number) => bridge.getGroupNotice(groupId),
getCookiesStr: (domain: string) => bridge.getCookiesStr(domain),
getCsrfToken: () => bridge.getCsrfToken(),
getCredentials: (domain: string) => bridge.getCredentials(domain),
};
}