57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package example
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// ExaFile 文件实体
|
|
type ExaFile struct {
|
|
ID uint
|
|
FileName string
|
|
FileMd5 string
|
|
FilePath string
|
|
ChunkTotal int
|
|
IsFinish bool
|
|
ExaFileChunk []ExaFileChunk
|
|
}
|
|
|
|
// ExaFileChunk 文件切片实体
|
|
type ExaFileChunk struct {
|
|
ID uint
|
|
ExaFileID uint
|
|
FileChunkNumber int
|
|
FileChunkPath string
|
|
}
|
|
|
|
// BreakpointContinueRepo 断点续传仓储接口
|
|
type BreakpointContinueRepo interface {
|
|
FindOrCreateFile(ctx context.Context, fileMd5, fileName string, chunkTotal int) (*ExaFile, error)
|
|
CreateFileChunk(ctx context.Context, fileID uint, fileChunkPath string, fileChunkNumber int) error
|
|
DeleteFileChunk(ctx context.Context, fileMd5, filePath string) error
|
|
}
|
|
|
|
// BreakpointContinueUsecase 断点续传用例
|
|
type BreakpointContinueUsecase struct {
|
|
repo BreakpointContinueRepo
|
|
}
|
|
|
|
// NewBreakpointContinueUsecase 创建断点续传用例
|
|
func NewBreakpointContinueUsecase(repo BreakpointContinueRepo) *BreakpointContinueUsecase {
|
|
return &BreakpointContinueUsecase{repo: repo}
|
|
}
|
|
|
|
// FindOrCreateFile 查找或创建文件记录
|
|
func (uc *BreakpointContinueUsecase) FindOrCreateFile(ctx context.Context, fileMd5, fileName string, chunkTotal int) (*ExaFile, error) {
|
|
return uc.repo.FindOrCreateFile(ctx, fileMd5, fileName, chunkTotal)
|
|
}
|
|
|
|
// CreateFileChunk 创建文件切片记录
|
|
func (uc *BreakpointContinueUsecase) CreateFileChunk(ctx context.Context, fileID uint, fileChunkPath string, fileChunkNumber int) error {
|
|
return uc.repo.CreateFileChunk(ctx, fileID, fileChunkPath, fileChunkNumber)
|
|
}
|
|
|
|
// DeleteFileChunk 删除文件切片记录
|
|
func (uc *BreakpointContinueUsecase) DeleteFileChunk(ctx context.Context, fileMd5, filePath string) error {
|
|
return uc.repo.DeleteFileChunk(ctx, fileMd5, filePath)
|
|
}
|