瀏覽代碼

CollectionService: Add collection delete V3 for empty collections

Neeraj Gupta 2 年之前
父節點
當前提交
b59e681fdc
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      lib/services/collections_service.dart

+ 23 - 0
lib/services/collections_service.dart

@@ -392,6 +392,29 @@ class CollectionsService {
     }
   }
 
+  Future<void> trashEmptyCollections(Collection collection) async {
+    try {
+      // While trashing empty albums, we must pass keeFiles flag as True.
+      // The server will verify that the collection is actually empty before
+      // deleting the files. If keepFiles is set as False and the collection
+      // is not empty, then the files in the collections will be moved to trash
+      await _enteDio.delete(
+        "/collections/v3/${collection.id}?keepFiles=True&collectionID=${collection.id}",
+      );
+      final deletedCollection = collection.copyWith(isDeleted: true);
+      _collectionIDToCollections[collection.id] = deletedCollection;
+      unawaited(_db.insert([deletedCollection]));
+    } on DioError catch (e) {
+      if (e.response != null) {
+        debugPrint("Error " + e.response!.toString());
+      }
+      rethrow;
+    } catch (e) {
+      _logger.severe('failed to trash empty collection', e);
+      rethrow;
+    }
+  }
+
   Future<void> _handleCollectionDeletion(Collection collection) async {
     await _filesDB.deleteCollection(collection.id);
     final deletedCollection = collection.copyWith(isDeleted: true);