import { FileBuffer } from './file-buffer.interface'; import { UploadOptions } from './upload-options.interface'; import { FileMetadata } from './file-metadata.interface'; /** 存储提供者接口 */ export interface IStorageProvider { /** 提供者名称 */ name: string; /** 上传文件 */ upload(file: FileBuffer, options: UploadOptions): Promise; /** 下载文件 */ download(path: string): Promise; /** 删除文件 */ delete(path: string): Promise; /** 批量删除 */ deleteBatch(paths: string[]): Promise; /** 检查文件是否存在 */ exists(path: string): Promise; /** 获取文件元数据 */ getMetadata(path: string): Promise; /** 获取预签名URL */ getSignedUrl(path: string, expiresIn?: number): Promise; /** 获取预签名上传URL(用于客户端直传) */ getSignedUploadUrl(path: string, expiresIn?: number, contentType?: string): Promise; /** 复制文件 */ copy(sourcePath: string, destinationPath: string): Promise; /** 移动文件 */ move(sourcePath: string, destinationPath: string): Promise; /** 列出文件 */ list(prefix?: string, limit?: number): Promise; /** 初始化存储配置 */ initialize(): Promise; /** 健康检查 */ healthCheck(): Promise; } /** 上传结果 */ export interface UploadResult { /** 文件路径/键 */ key: string; /** 访问URL */ url?: string; /** ETag */ etag?: string; /** 版本ID(如果支持) */ versionId?: string; /** 文件大小 */ size: number; /** 上传时间 */ uploadedAt: Date; /** 额外元数据 */ metadata?: Record; } /** 批量删除结果 */ export interface BatchDeleteResult { /** 成功删除的文件列表 */ deleted: string[]; /** 删除失败的文件列表 */ failed: Array<{ path: string; error: string; }>; /** 总数 */ total: number; } /** 复制结果 */ export interface CopyResult { /** 目标路径 */ destinationPath: string; /** 文件大小 */ size: number; /** 复制时间 */ copiedAt: Date; /** ETag */ etag?: string; } /** 移动结果 */ export interface MoveResult { /** 目标路径 */ destinationPath: string; /** 文件大小 */ size: number; /** 移动时间 */ movedAt: Date; /** ETag */ etag?: string; } /** 列表结果 */ export interface ListResult { /** 文件列表 */ files: Array<{ key: string; size: number; lastModified: Date; etag?: string; }>; /** 是否还有更多文件 */ hasMore: boolean; /** 下一个标记 */ nextMarker?: string; /** 总数(如果支持) */ totalCount?: number; } /** 预签名上传信息 */ export interface PreSignedUploadInfo { /** 上传URL */ url: string; /** HTTP方法 */ method: 'PUT' | 'POST'; /** 需要的头部 */ headers: Record; /** 表单字段(如果使用POST) */ fields?: Record; /** 过期时间 */ expiresAt: Date; } /** 健康状态 */ export interface HealthStatus { /** 是否健康 */ healthy: boolean; /** 响应时间(毫秒) */ responseTime: number; /** 错误信息 */ error?: string; /** 额外信息 */ details?: Record; } /** 本地存储选项 */ export interface LocalStorageOptions { /** 上传根目录 */ uploadPath: string; /** 基础URL */ baseUrl?: string; /** 是否创建子目录 */ createSubdirectories?: boolean; /** 子目录格式(date: YYYY/MM/DD, hash: AB/CD/EF) */ subdirectoryFormat?: 'none' | 'date' | 'hash'; /** 最大文件大小 */ maxSize?: number; /** 文件权限 */ fileMode?: string; /** 目录权限 */ dirMode?: string; } /** S3存储选项 */ export interface S3StorageOptions { /** AWS访问密钥ID */ accessKeyId: string; /** AWS秘密访问密钥 */ secretAccessKey: string; /** AWS区域 */ region: string; /** S3存储桶名称 */ bucket: string; /** 自定义端点 */ endpoint?: string; /** ACL(访问控制列表) */ acl?: string; /** 服务器端加密 */ serverSideEncryption?: string; /** 存储类别 */ storageClass?: string; /** 是否启用CDN */ cdnEnabled?: boolean; /** CDN域名 */ cdnDomain?: string; /** 是否使用路径样式访问 */ forcePathStyle?: boolean; /** 签名版本 */ signatureVersion?: string; } /** OSS存储选项 */ export interface OSSStorageOptions { /** Access Key ID */ accessKeyId: string; /** Access Key Secret */ accessKeySecret: string; /** OSS区域 */ region: string; /** OSS Bucket名称 */ bucket: string; /** 内网域名 */ internalEndpoint?: string; /** 外网域名 */ externalEndpoint?: string; /** 安全令牌(STS) */ securityToken?: string; /** 访问权限 */ acl?: string; /** 服务器端加密 */ serverSideEncryption?: string; /** 是否启用CDN */ cdnEnabled?: boolean; /** CDN加速域名 */ cdnDomain?: string; } /** MinIO存储选项 */ export interface MinIOStorageOptions { /** 端点URL */ endPoint: string; /** 端口 */ port: number; /** 是否使用SSL */ useSSL: boolean; /** Access Key */ accessKey: string; /** Secret Key */ secretKey: string; /** Bucket名称 */ bucket: string; /** Region */ region?: string; /** 是否启用CDN */ cdnEnabled?: boolean; /** CDN域名 */ cdnDomain?: string; } /** 存储配置 */ export interface StorageConfig { /** 存储提供者类型 */ provider: 'local' | 's3' | 'oss' | 'minio'; /** 提供者特定配置 */ options: LocalStorageOptions | S3StorageOptions | OSSStorageOptions | MinIOStorageOptions; /** 是否启用备份 */ backup?: { enabled: boolean; provider: StorageConfig['provider']; options: StorageConfig['options']; }; /** 是否启用镜像 */ mirror?: { enabled: boolean; providers: Array; }; /** 缓存配置 */ cache?: { enabled: boolean; ttl: number; maxSize: number; }; }