feat(reset): 以构造器模式重构

- 加了大文件传输自定义分片协议

BREAKING CHANGES: 0.1.0(latest)
This commit is contained in:
tobegold574
2025-11-30 20:27:53 +08:00
parent c5853847ae
commit 382e3aff21
82 changed files with 1421 additions and 7010 deletions

77
types/upload/api.ts Normal file
View File

@@ -0,0 +1,77 @@
// 分片上传相关的API接口定义
/**
* 文件分片请求接口
*/
export interface UploadChunkRequest {
/** 文件唯一标识 */
fileId: string;
/** 分片索引从0开始 */
chunkIndex: number;
/** 总分片数量 */
totalChunks: number;
/** 分片大小 */
chunkSize: number;
/** 文件总大小 */
totalSize: number;
/** 文件名称 */
fileName: string;
/** 文件类型 */
fileType: string;
}
/**
* 文件分片响应接口
*/
export interface UploadChunkResponse {
success: boolean;
message: string;
chunkIndex: number;
uploadedSize: number;
isLastChunk?: boolean;
}
/**
* 合并分片请求接口
*/
export interface MergeChunksRequest {
/** 文件唯一标识 */
fileId: string;
/** 总分片数量 */
totalChunks: number;
/** 文件名称 */
fileName: string;
/** 文件类型 */
fileType: string;
/** 文件总大小 */
totalSize: number;
}
/**
* 合并分片响应接口
*/
export interface MergeChunksResponse {
success: boolean;
message: string;
fileUrl?: string;
fileId: string;
fileSize: number;
}
/**
* 检查文件上传状态请求接口
*/
export interface CheckUploadStatusRequest {
/** 文件唯一标识 */
fileId: string;
}
/**
* 检查文件上传状态响应接口
*/
export interface CheckUploadStatusResponse {
success: boolean;
isUploaded: boolean;
uploadedChunks: number[];
totalChunks?: number;
}

63
types/upload/base.ts Normal file
View File

@@ -0,0 +1,63 @@
// 上传相关的基础类型定义
/**
* 上传状态枚举
*/
export enum UploadStatus {
/** 初始状态 */
INITIAL = 'INITIAL',
/** 上传中 */
UPLOADING = 'UPLOADING',
/** 暂停 */
PAUSED = 'PAUSED',
/** 已完成 */
COMPLETED = 'COMPLETED',
/** 失败 */
FAILED = 'FAILED'
}
/**
* 文件分片信息
*/
export interface FileChunk {
/** 分片索引 */
index: number;
/** 分片大小 */
size: number;
/** 分片起始位置 */
start: number;
/** 分片结束位置 */
end: number;
/** 是否已上传 */
uploaded?: boolean;
}
/**
* 上传任务信息
*/
export interface UploadTask {
/** 任务ID */
taskId: string;
/** 文件ID */
fileId: string;
/** 文件信息 */
file: File;
/** 上传状态 */
status: UploadStatus;
/** 已上传大小 */
uploadedSize: number;
/** 总大小 */
totalSize: number;
/** 上传进度百分比 */
progress: number;
/** 分片大小 */
chunkSize: number;
/** 总分片数 */
totalChunks: number;
/** 已上传分片索引列表 */
uploadedChunks: number[];
/** 创建时间 */
createdAt: number;
/** 更新时间 */
updatedAt: number;
}

3
types/upload/index.ts Normal file
View File

@@ -0,0 +1,3 @@
// 导出上传相关的类型定义
export * from './api';
export * from './base';