import { FileType } from '../enums/file-type.enum'; import { Request } from 'express'; /** * 文件上传选项 */ export interface FileUploadOptions { /** 文件大小限制(字节),默认 10MB */ maxSize?: number; /** 允许的文件类型(FileType 枚举或 MIME 类型) */ types?: Array; /** 允许的扩展名 */ exts?: string[]; /** 需要认证 */ auth?: boolean; /** 需要文件所有权 */ ownership?: boolean; /** 公开访问 */ public?: boolean; /** 病毒扫描: true=强制, false=禁用, 'auto'=智能(默认) */ scan?: boolean | 'auto'; /** 文件名清理,默认 true */ sanitize?: boolean; /** 保留原始文件名(默认 false,使用 UUID)*/ preserveOriginalName?: boolean; /** 是否启用文件签名验证(默认 true) */ validateSignature?: boolean; /** 是否启用恶意文件检测 */ maliciousCheck?: boolean; image?: { /** 调整大小 */ resize?: { width: number; height: number; fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside'; }; /** 压缩质量 0-100 */ quality?: number; /** 输出格式 */ format?: 'jpeg' | 'png' | 'webp'; /** 水印文字 */ watermark?: string; /** 生成缩略图 */ thumbnail?: boolean; }; processor?: string | { name: string; options?: any; }; /** 处理器选项(会与 processor.options 合并) */ processorOptions?: any; /** 存储提供者: 'local' | 's3' | 'oss' | 'minio' */ storage?: string; /** 自定义存储路径 */ path?: string; /** 上传前钩子 */ before?: (file: Express.Multer.File, context: UploadContext) => Promise; /** 上传后钩子 */ after?: (file: Express.Multer.File, context: UploadContext) => Promise; } /** * 上传上下文 */ export interface UploadContext { /** 共享数据 */ shared: Record; /** 获取处理器 */ getProcessor(name: string): any | null; /** 保存文件元数据 */ saveMetadata(fileId: string, metadata: any): Promise; /** 获取当前用户 */ getUser(): any; /** 获取请求对象 */ getRequest(): Request; }