diff --git a/src/onebot/action/stream/UploadFileStream.ts b/src/onebot/action/stream/UploadFileStream.ts index 64075b91..ef5a7e39 100644 --- a/src/onebot/action/stream/UploadFileStream.ts +++ b/src/onebot/action/stream/UploadFileStream.ts @@ -7,6 +7,7 @@ import fs from 'fs'; import { join as joinPath } from 'node:path'; import { randomUUID } from 'crypto'; import { createHash } from 'crypto'; +import { unlink } from 'node:fs'; // 简化配置 const CONFIG = { @@ -25,7 +26,8 @@ const SchemaData = Type.Object({ is_complete: Type.Optional(Type.Boolean()), filename: Type.Optional(Type.String()), reset: Type.Optional(Type.Boolean()), - verify_only: Type.Optional(Type.Boolean()) + verify_only: Type.Optional(Type.Boolean()), + file_retention: Type.Number({ default: 5 * 60 * 1000 }) // 默认5分钟 回收 不设置或0为不回收 }); type Payload = Static; @@ -47,6 +49,7 @@ interface StreamState { memoryChunks?: Map; tempDir?: string; finalPath?: string; + fileRetention?: number; // 管理 createdAt: number; @@ -131,9 +134,9 @@ export class UploadFileStream extends OneBotAction 0) { + setTimeout(() => { + unlink(finalPath, err => { + this.core.context.logger.logError(`Failed to delete retained file ${finalPath}:`, err); + }); + }, stream.fileRetention); + } return { type: StreamStatus.Response, stream_id: stream.id,