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.
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { join } from 'node:path';
|
|
import { readdir, unlink } from 'node:fs/promises';
|
|
import { Type } from '@sinclair/typebox';
|
|
|
|
export class CleanStreamTempFile extends OneBotAction<void, void> {
|
|
override actionName = ActionName.CleanStreamTempFile;
|
|
override payloadSchema = Type.Object({});
|
|
override returnSchema = Type.Null();
|
|
|
|
async _handle (_payload: void): Promise<void> {
|
|
try {
|
|
// 获取临时文件夹路径
|
|
const tempPath = this.core.NapCatTempPath;
|
|
|
|
// 读取文件夹中的所有文件
|
|
const files = await readdir(tempPath);
|
|
|
|
// 删除每个文件
|
|
const deletePromises = files.map(async (file) => {
|
|
const filePath = join(tempPath, file);
|
|
try {
|
|
await unlink(filePath);
|
|
this.core.context.logger.log(`已删除文件: ${filePath}`);
|
|
} catch (err: unknown) {
|
|
this.core.context.logger.log(`删除文件 ${filePath} 失败: ${(err as Error).message}`);
|
|
}
|
|
});
|
|
await Promise.all(deletePromises);
|
|
} catch (err: unknown) {
|
|
this.core.context.logger.log(`清理流临时文件失败: ${(err as Error).message}`);
|
|
}
|
|
}
|
|
}
|