优化结构

This commit is contained in:
Yvan
2026-08-28 16:37:53 +08:00
parent 295ee5c49e
commit 6f9908d926
14 changed files with 56 additions and 58 deletions
+9 -3
View File
@@ -90,11 +90,17 @@ func (r *mediaRepo) FailUploadSession(ctx context.Context, id uint) error {
return r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("id = ?", id).Update("status", "failed").Error
}
func (r *mediaRepo) CompleteUploadSession(ctx context.Context, id uint, key string, mediaID uint) error {
return r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("id = ?", id).Updates(map[string]any{"status": "completed", "storage_key": key, "media_id": mediaID}).Error
result := r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("id = ? AND status = ?", id, "merging").Updates(map[string]any{"status": "completed", "storage_key": key, "media_id": mediaID})
if result.Error != nil {
return result.Error
}
if result.RowsAffected != 1 {
return system.ErrUploadSessionNotFound
}
return nil
}
func (r *mediaRepo) DeleteUploadSession(ctx context.Context, id uint) error {
// The compatible flow uses GORM's normal Delete here, retaining the soft-deleted session
// for audit/recovery rather than physically removing it.
// Upload sessions are staging records; cleanup physically removes them and their chunks.
return r.data.DB().WithContext(ctx).Unscoped().Delete(&uploadSessionPO{}, id).Error
}
func (r *mediaRepo) UpsertChunk(ctx context.Context, uploadID uint, v *system.UploadChunk) error {