diff --git a/models/file.go b/models/file.go index 161bbbb8d4..8a7b3c8ec3 100644 --- a/models/file.go +++ b/models/file.go @@ -234,7 +234,7 @@ func DeleteFiles(files []*File, uid uint) error { user.ID = uid var size uint64 for _, file := range files { - if file.UserID != uid { + if uid > 0 && file.UserID != uid { tx.Rollback() return errors.New("user id not consistent") } @@ -253,9 +253,11 @@ func DeleteFiles(files []*File, uid uint) error { size += file.Size } - if err := user.ChangeStorage(tx, "-", size); err != nil { - tx.Rollback() - return err + if uid > 0 { + if err := user.ChangeStorage(tx, "-", size); err != nil { + tx.Rollback() + return err + } } return tx.Commit().Error diff --git a/service/admin/file.go b/service/admin/file.go index 84d8129686..8279c788e7 100644 --- a/service/admin/file.go +++ b/service/admin/file.go @@ -103,15 +103,22 @@ func (service *FileBatchService) Delete(c *gin.Context) serializer.Response { // 异步执行删除 go func(files map[uint][]model.File) { for uid, file := range files { + var ( + fs *filesystem.FileSystem + err error + ) user, err := model.GetUserByID(uid) if err != nil { - continue - } - - fs, err := filesystem.NewFileSystem(&user) - if err != nil { - fs.Recycle() - continue + fs, err = filesystem.NewAnonymousFileSystem() + if err != nil { + continue + } + } else { + fs, err = filesystem.NewFileSystem(&user) + if err != nil { + fs.Recycle() + continue + } } // 汇总文件ID