mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-13 00:10:27 +00:00
- 将 == 改为 === 进行严格相等检查 - 修复未使用的变量,改为 _varName 格式 - 移除箭头函数中缺少的返回值 - 将 void 改为 undefined - 移除无用的构造函数 - 修复 Promise 参数命名规范 - 移除不必要的转义符 - 添加 Service Worker 全局变量声明 - 修复未使用的类型参数
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
export const GetCredentialsPayloadSchema = Type.Object({
|
|
domain: Type.String({ description: '需要获取 cookies 的域名' }),
|
|
});
|
|
|
|
export type GetCredentialsPayload = Static<typeof GetCredentialsPayloadSchema>;
|
|
|
|
export const GetCredentialsReturnSchema = Type.Object({
|
|
cookies: Type.String({ description: 'Cookies' }),
|
|
token: Type.Number({ description: 'CSRF Token' }),
|
|
});
|
|
|
|
export type GetCredentialsResponse = Static<typeof GetCredentialsReturnSchema>;
|
|
|
|
export class GetCredentials extends OneBotAction<GetCredentialsPayload, GetCredentialsResponse> {
|
|
override actionName = ActionName.GetCredentials;
|
|
override payloadSchema = GetCredentialsPayloadSchema;
|
|
override returnSchema = GetCredentialsReturnSchema;
|
|
override actionSummary = '获取登录凭证';
|
|
override actionDescription = '获取登录凭证';
|
|
override actionTags = ['系统接口'];
|
|
override payloadExample = {
|
|
domain: 'qun.qq.com',
|
|
};
|
|
|
|
override returnExample = {
|
|
cookies: 'uin=o123456789; skey=@abc12345;',
|
|
token: 123456789,
|
|
};
|
|
|
|
async _handle (payload: GetCredentialsPayload) {
|
|
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
|
// 把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
|
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
|
const bkn = cookiesObject?.['skey'] ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
|
return { cookies, token: +bkn };
|
|
}
|
|
}
|