mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 21:10:23 +00:00
Add payload and return schemas to OneBot actions
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.
This commit is contained in:
@@ -7,20 +7,21 @@ import fs from 'fs';
|
||||
import { imageSizeFallBack } from 'napcat-image-size';
|
||||
import { BaseDownloadStream, DownloadResult } from './BaseDownloadStream';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
file: Type.Optional(Type.String()),
|
||||
file_id: Type.Optional(Type.String()),
|
||||
chunk_size: Type.Optional(Type.Number({ default: 64 * 1024 })), // 默认64KB分块
|
||||
export const DownloadFileImageStreamPayloadSchema = Type.Object({
|
||||
file: Type.Optional(Type.String({ description: '文件路径或 URL' })),
|
||||
file_id: Type.Optional(Type.String({ description: '文件 ID' })),
|
||||
chunk_size: Type.Optional(Type.Number({ default: 64 * 1024, description: '分块大小 (字节)' })), // 默认64KB分块
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
export type DownloadFileImageStreamPayload = Static<typeof DownloadFileImageStreamPayloadSchema>;
|
||||
|
||||
export class DownloadFileImageStream extends BaseDownloadStream<Payload, DownloadResult> {
|
||||
export class DownloadFileImageStream extends BaseDownloadStream<DownloadFileImageStreamPayload, DownloadResult> {
|
||||
override actionName = ActionName.DownloadFileImageStream;
|
||||
override payloadSchema = SchemaData;
|
||||
override payloadSchema = DownloadFileImageStreamPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '下载结果 (流式)' });
|
||||
override useStream = true;
|
||||
|
||||
async _handle (payload: Payload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit): Promise<StreamPacket<DownloadResult>> {
|
||||
async _handle (payload: DownloadFileImageStreamPayload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit): Promise<StreamPacket<DownloadResult>> {
|
||||
try {
|
||||
payload.file ||= payload.file_id || '';
|
||||
const chunkSize = payload.chunk_size || 64 * 1024;
|
||||
|
||||
Reference in New Issue
Block a user