diff --git a/internal/app/dao/matter.go b/internal/app/dao/matter.go index 3eabf6d..21febda 100644 --- a/internal/app/dao/matter.go +++ b/internal/app/dao/matter.go @@ -136,14 +136,9 @@ func (ms *Matter) Remove(mid int64, trashedBy string) error { return gdb.Model(&model.Matter{Id: mid}).Updates(values).Error } -func (ms *Matter) RemoveToRecycle(alias string) error { - m, err := ms.Find(alias) - if err != nil { - return err - } - +func (ms *Matter) RemoveToRecycle(m *model.Matter) error { // soft delete the matter - if err := ms.Remove(m.Id, alias); err != nil { + if err := ms.Remove(m.Id, m.Alias); err != nil { return err } @@ -151,7 +146,7 @@ func (ms *Matter) RemoveToRecycle(alias string) error { rm := &model.Recycle{ Uid: m.Uid, Sid: m.Sid, - Alias: alias, + Alias: m.Alias, Name: m.Name, Type: m.Type, Size: m.Size, diff --git a/internal/app/model/storage.go b/internal/app/model/storage.go index e6dd69f..8ece7e8 100644 --- a/internal/app/model/storage.go +++ b/internal/app/model/storage.go @@ -8,7 +8,7 @@ import ( const ( StorageModeNetDisk = iota + 1 - StorageModeFileDisk + StorageModeOutline ) const ( @@ -42,7 +42,7 @@ func (Storage) TableName() string { } func (s *Storage) PublicRead() bool { - return s.Mode == StorageModeFileDisk + return s.Mode == StorageModeOutline } func (s *Storage) SKAsterisk() (sk string) { diff --git a/internal/pkg/fakefs/file.go b/internal/pkg/fakefs/file.go index fbe0bae..87bab4a 100644 --- a/internal/pkg/fakefs/file.go +++ b/internal/pkg/fakefs/file.go @@ -139,12 +139,34 @@ func (f *File) Move(uid int64, alias, parent string) error { } func (f *File) Delete(uid int64, alias string) error { - _, err := f.dMatter.FindUserMatter(uid, alias) + matter, err := f.dMatter.FindUserMatter(uid, alias) if err != nil { return err } - return f.dMatter.RemoveToRecycle(alias) + storage, err := f.sStorage.Get(matter.Sid) + if err != nil { + return err + } + + if storage.Mode == model.StorageModeNetDisk { + return f.dMatter.RemoveToRecycle(matter) + } + + return f.removeFromStorage(matter, storage) +} + +func (f *File) removeFromStorage(m *model.Matter, s *model.Storage) error { + provider, err := f.sStorage.GetProviderByStorage(s) + if err != nil { + return err + } + + if err := provider.ObjectDelete(m.Object); err != nil { + return err + } + + return f.dMatter.Remove(m.Id, m.Alias) } func (f *File) copyOrMoveValidation(m *model.Matter, uid int64, parent string) error { diff --git a/internal/pkg/fakefs/folder.go b/internal/pkg/fakefs/folder.go index fb9a733..b920a73 100644 --- a/internal/pkg/fakefs/folder.go +++ b/internal/pkg/fakefs/folder.go @@ -107,7 +107,7 @@ func (f *Folder) Remove(uid int64, alias string) error { } } - return f.dMatter.RemoveToRecycle(m.Alias) + return f.dMatter.RemoveToRecycle(m) } func (f *Folder) copyOrMoveValidation(m *model.Matter, uid int64, parent string) error {