feat(fileupload): 并入通用大文件分片上传服务端核心

- 六接口(init/chunk/merge/check/task/abort)+ 分片幂等 + 断点续传 +
  .part 原子改名 + 合并整文件 MD5 校验 + 秒传
- 零宿主耦合:Repository 接口注入存储、Envelope 注入响应封装、
  OnMerged/OnInstantHit 回调衔接业务(仅依赖既有 gin/uuid)
- 自 FileUpload 项目 restful/upload 抽出;maintain-service 云端文件为其首个宿主
This commit is contained in:
2026-09-25 15:11:30 +08:00
parent 40c9f62c9f
commit 33574d4ac2
5 changed files with 711 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package fileupload
// Repository 存储层接口:宿主用自己的 ORM/表结构实现(本包不关心表怎么建)。
// 语义约定:
// - Delete* 为软删或硬删由宿主决定,但之后 GetTaskByUploadID / 各 Find 必须查不到;
// - Find* 只需返回未删除的最新一条。
type Repository interface {
// CreateTask 新建任务(Id/UploadId 已由本包赋值)。
CreateTask(t *TaskInfo) error
// GetTaskByUploadID 按 uploadId 取未删除任务;不存在返回 (nil, nil)。
GetTaskByUploadID(uploadID string) (*TaskInfo, error)
// FindDoneByMD5 取同 MD5 已完成任务中最新一条;无则 (nil, nil)。
FindDoneByMD5(md5 string) (*TaskInfo, error)
// FindUploadingByMD5 取同 MD5 进行中任务一条(断点续传);无则 (nil, nil)。
FindUploadingByMD5(md5 string) (*TaskInfo, error)
// UpdateTaskMerged 合并成功:置 done 并记录 storagePath。
UpdateTaskMerged(id int64, storagePath string) error
// SetTaskStatus 更新任务状态(error/merging 等流转)。
SetTaskStatus(id int64, status string) error
// CountChunks 统计任务已确认分片数。
CountChunks(uploadID string) (int, error)
// ChunkExists 分片是否已确认(幂等依据)。
ChunkExists(uploadID string, index int32) (bool, error)
// CreateChunk 写入分片确认记录。
CreateChunk(c *ChunkInfo) error
// ListChunkIndexes 已确认分片序号升序。
ListChunkIndexes(uploadID string) ([]int32, error)
// DeleteChunks 删除任务的分片记录。
DeleteChunks(uploadID string) error
// DeleteTaskByUploadID 删除任务。
DeleteTaskByUploadID(uploadID string) error
}