mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
528240026d
- make format 现在与 code-check 使用同一格式化器(golangci-lint fmt),消除 goimports -local 与 gofumpt 的格式拉锯 - .golangci.yml 关闭默认 50/3 截断,完整上报所有问题(只增强不弱化) - 全库 gofumpt 规范化(203 files, 纯格式无行为变更)
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package ingest
|
|
|
|
import (
|
|
"Wavelet/plugins/domain/upload/models"
|
|
"Wavelet/plugins/domain/upload/repository"
|
|
"Wavelet/plugins/domain/upload/shared"
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
uploadcache "Wavelet/plugins/domain/upload/cache"
|
|
|
|
uploadstats "Wavelet/plugins/domain/upload/stats"
|
|
)
|
|
|
|
// Remove soft-deletes an upload and decrements incremental stats.
|
|
func Remove(ctx context.Context, uploadID uint64) (models.Upload, error) {
|
|
upload, err := repository.GetActiveUploadByID(ctx, uploadID)
|
|
if err != nil {
|
|
return models.Upload{}, err
|
|
}
|
|
if err := softDeleteUploadWithStats(ctx, &upload); err != nil {
|
|
return models.Upload{}, err
|
|
}
|
|
upload.Status = models.UploadStatusDeleted
|
|
return upload, nil
|
|
}
|
|
|
|
// RemoveOwned soft-deletes an upload owned by userID and decrements incremental stats.
|
|
func RemoveOwned(ctx context.Context, userID, uploadID uint64) (models.Upload, error) {
|
|
upload, err := repository.GetActiveUploadByID(ctx, uploadID)
|
|
if err != nil {
|
|
return models.Upload{}, err
|
|
}
|
|
if upload.UserID != userID {
|
|
return models.Upload{}, ErrForbidden
|
|
}
|
|
if err := softDeleteUploadWithStats(ctx, &upload); err != nil {
|
|
return models.Upload{}, err
|
|
}
|
|
upload.Status = models.UploadStatusDeleted
|
|
return upload, nil
|
|
}
|
|
|
|
func softDeleteUploadWithStats(ctx context.Context, upload *models.Upload) error {
|
|
statsSnapshot := *upload
|
|
db := shared.GetDB(ctx)
|
|
if db != nil {
|
|
if err := db.Transaction(func(tx *gorm.DB) error {
|
|
if err := repository.SoftDeleteUploadTx(tx, upload); err != nil {
|
|
return err
|
|
}
|
|
return uploadstats.ApplyUploadStatsDeltaTx(tx, &statsSnapshot, -1)
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
uploadcache.EvictUploadMeta(ctx, upload.ID)
|
|
return nil
|
|
}
|