Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Sketch

Manav Rathib3776600e635
diff --git a/web/packages/gallery/services/files-db.ts b/web/packages/gallery/services/files-db.ts
index c1887e9e95..d7b27a105a 100644
--- a/web/packages/gallery/services/files-db.ts
+++ b/web/packages/gallery/services/files-db.ts
@@ -106,6 +106,7 @@ const LocalCollection = z
encryptedName,
nameDecryptionNonce,
attributes,
+ isDeleted,
...rest
} = c;
ignore([
@@ -114,6 +115,7 @@ const LocalCollection = z
encryptedName,
nameDecryptionNonce,
attributes,
+ isDeleted,
]);
return rest;
});
diff --git a/web/packages/new/photos/services/collections.ts b/web/packages/new/photos/services/collections.ts
index f64b839a54..d90ac6f359 100644
--- a/web/packages/new/photos/services/collections.ts
+++ b/web/packages/new/photos/services/collections.ts
@@ -125,7 +125,7 @@ export const syncCollections = async () => {
const TRASH_TIME = "trash-time";
const DELETED_COLLECTION = "deleted-collection";
-export async function getLocalDeletedCollections() {
+async function getLocalDeletedCollections() {
const trashedCollections: Collection[] =
(await localForage.getItem<Collection[]>(DELETED_COLLECTION)) || [];
const nonUndefinedCollections = trashedCollections.filter(
@@ -204,10 +204,7 @@ export async function syncTrash(
const collectionID = trashItem.file.collectionID;
let collection = collectionByID.get(collectionID);
if (!collection) {
- // We might not have the collection locally since it
- // might've been deleted. We still need the collection since
- // the trash item will be encrypted using the (erstwhile)
- // collection's key.
+ // See: [Note: Trash item collection keys]
collection = await getCollectionByID(collectionID);
collectionByID.set(collectionID, collection);
await localForage.setItem(DELETED_COLLECTION, [
diff --git a/web/packages/new/photos/services/photos-fdb.ts b/web/packages/new/photos/services/photos-fdb.ts
index 00123ec499..bef8d5735f 100644
--- a/web/packages/new/photos/services/photos-fdb.ts
+++ b/web/packages/new/photos/services/photos-fdb.ts
@@ -33,3 +33,33 @@ export const savedCollections = async (): Promise<Collection[]> =>
*/
export const saveCollections = (collections: Collection[]) =>
localForage.setItem("collections", collections);
+
+/**
+ * Return keys of (potentially deleted) collections referred to by trash items
+ * present in our local database.
+ *
+ * Use {@link saveTrashItemCollectionKeys} to update the database.
+ *
+ * [Note: Trash item collection keys]
+ *
+ * Trash items are erstwhile files, and like collection files, they need a
+ * collection key to decrypt them.
+ *
+ * However, it is possible that the collection which contained the file was also
+ * deleted. Such deleted collections will not be present in the list returned by
+ * {@link savedCollections}.
+ *
+ * So to still be able to access the collection keys in order to process the
+ * trash item, we separately save a list of {collectionID, collectionKey} pairs.
+ *
+ * - This list contains only collectionsIDs for which there is a corresponding
+ * local trash item.
+ *
+ * - During each trash sync, this list is seeded using {@link savedCollections}.
+ * Then, whenever we encounter a collection which is not present locally
+ * (since it might've been deleted), we fetch it from remote and add an entry
+ * for it in {@link savedTrashItemCollectionKeys}.
+ *
+ * - Once the sync completes, we updated this list to retain only entries that
+ * are still referred to by items remaining in the trash.
+ */