mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 07:01:16 +00:00
Introduced explicit payloadSchema and returnSchema definitions for all OneBotAction classes using @sinclair/typebox. This improves type safety, API documentation, and validation for action payloads and return values. Also refactored method signatures and types for consistency across the codebase.
26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
export const GetFlashFileUrlPayloadSchema = Type.Object({
|
|
fileset_id: Type.String({ description: '文件集 ID' }),
|
|
file_name: Type.Optional(Type.String({ description: '文件名' })),
|
|
file_index: Type.Optional(Type.Number({ description: '文件索引' })),
|
|
});
|
|
|
|
export type GetFlashFileUrlPayload = Static<typeof GetFlashFileUrlPayloadSchema>;
|
|
|
|
export class GetFlashFileUrl extends OneBotAction<GetFlashFileUrlPayload, any> {
|
|
override actionName = ActionName.GetFlashFileUrl;
|
|
override payloadSchema = GetFlashFileUrlPayloadSchema;
|
|
override returnSchema = Type.Any({ description: '文件下载链接' });
|
|
|
|
async _handle (payload: GetFlashFileUrlPayload) {
|
|
// 文件的索引依旧从0开始
|
|
return await this.core.apis.FlashApi.getFileTransUrl(payload.fileset_id, {
|
|
fileName: payload.file_name,
|
|
fileIndex: payload.file_index,
|
|
});
|
|
}
|
|
}
|