build: 1.3.5-beta33

This commit is contained in:
手瓜一十雪 committed 2024-05-18 13:35:57 +08:00
1 parent 3e8d8817bb
commit db8d30d27b
5 files changed
+11 -22

No files matched your search

+4 -15
View File
@@ -9,7 +9,7 @@ import Ajv from 'ajv';
interface FileResponse {
file: string;
}
const PayloadSchema = {
const SchemaData = {
type: 'object',
properties: {
thread_count: { type: 'number' },
@@ -17,7 +17,7 @@ const PayloadSchema = {
base64: { type: 'string' },
name: { type: 'string' },
headers: {
type: "array",
type: ["string", "array"],
items: {
type: "string"
}
@@ -25,22 +25,11 @@ const PayloadSchema = {
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof PayloadSchema>;
type Payload = FromSchema<typeof SchemaData>;
export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileResponse> {
actionName = ActionName.GoCQHTTP_DownloadFile;
validateDownload = new Ajv().compile(PayloadSchema);
// 这里重写是为了兼容 headers可能出现 string string[]
protected async check(payload: Payload): Promise<BaseCheckResult> {
if (payload.headers) {
// 如果存在headers 为数组则开始兼容string string[]
payload.headers = payload?.headers && Array.isArray(payload.headers) ? payload.headers : [payload.headers as unknown as string];
}
if (!this.validateDownload(payload)) {
return { valid: false, message: this.validateDownload.errors?.map(e => e.message).join(', ') as string };
}
return { valid: true };
}
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<FileResponse> {
const isRandomName = !payload.name;
const name = payload.name || uuid4();