Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update

Manav Rathi03f418245d61
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index 9d47f67d46..bae969cd94 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -11,7 +11,6 @@ import {
Collection,
CollectionMagicMetadata,
CollectionMagicMetadataProps,
- CollectionPublicMagicMetadata,
CollectionSubType,
type CollectionType,
EncryptedCollection,
@@ -389,84 +388,6 @@ export const updateCollectionMagicMetadata = async (
return updatedCollection;
};
-export const updateSharedCollectionMagicMetadata = async (
- collection: Collection,
- updatedMagicMetadata: CollectionMagicMetadata,
-) => {
- const token = getToken();
- if (!token) {
- return;
- }
-
- const { encryptedData, decryptionHeader } = await encryptMetadataJSON(
- updatedMagicMetadata.data,
- collection.key,
- );
- const reqBody: UpdateMagicMetadataRequest = {
- id: collection.id,
- magicMetadata: {
- version: updatedMagicMetadata.version,
- count: updatedMagicMetadata.count,
- data: encryptedData,
- header: decryptionHeader,
- },
- };
-
- await HTTPService.put(
- await apiURL("/collections/sharee-magic-metadata"),
- reqBody,
- null,
- { "X-Auth-Token": token },
- );
- const updatedCollection: Collection = {
- ...collection,
- magicMetadata: {
- ...updatedMagicMetadata,
- version: updatedMagicMetadata.version + 1,
- },
- };
- return updatedCollection;
-};
-
-export const updatePublicCollectionMagicMetadata = async (
- collection: Collection,
- updatedPublicMagicMetadata: CollectionPublicMagicMetadata,
-) => {
- const token = getToken();
- if (!token) {
- return;
- }
-
- const { encryptedData, decryptionHeader } = await encryptMetadataJSON(
- updatedPublicMagicMetadata.data,
- collection.key,
- );
- const reqBody: UpdateMagicMetadataRequest = {
- id: collection.id,
- magicMetadata: {
- version: updatedPublicMagicMetadata.version,
- count: updatedPublicMagicMetadata.count,
- data: encryptedData,
- header: decryptionHeader,
- },
- };
-
- await HTTPService.put(
- await apiURL("/collections/public-magic-metadata"),
- reqBody,
- null,
- { "X-Auth-Token": token },
- );
- const updatedCollection: Collection = {
- ...collection,
- pubMagicMetadata: {
- ...updatedPublicMagicMetadata,
- version: updatedPublicMagicMetadata.version + 1,
- },
- };
- return updatedCollection;
-};
-
export const renameCollection = async (
collection: Collection,
newCollectionName: string,
diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.ts
index 2ca1377a14..780bc3582b 100644
--- a/web/apps/photos/src/utils/collection.ts
+++ b/web/apps/photos/src/utils/collection.ts
@@ -7,7 +7,6 @@ import {
type Collection,
CollectionMagicMetadataProps,
type CollectionOrder,
- CollectionPublicMagicMetadataProps,
CollectionSubType,
} from "ente-media/collection";
import { EnteFile } from "ente-media/file";
@@ -23,6 +22,7 @@ import {
moveToCollection,
restoreToCollection,
updateCollectionOrder,
+ updateCollectionSortOrder,
updateCollectionVisibility,
} from "ente-new/photos/services/collection";
import {
@@ -40,7 +40,6 @@ import {
removeFromCollection,
unhideToCollection,
updateCollectionMagicMetadata,
- updatePublicCollectionMagicMetadata,
} from "services/collectionService";
import {
SetFilesDownloadProgressAttributes,
@@ -190,34 +189,16 @@ export const changeCollectionVisibility = async (
visibility: ItemVisibility,
) => updateCollectionVisibility(await collection1To2(collection), visibility);
-export const changeCollectionSortOrder = async (
- collection: Collection,
- asc: boolean,
-) => {
- try {
- const updatedPublicMagicMetadataProps: CollectionPublicMagicMetadataProps =
- { asc };
-
- const updatedPubMagicMetadata = await updateMagicMetadata(
- updatedPublicMagicMetadataProps,
- collection.pubMagicMetadata,
- collection.key,
- );
-
- await updatePublicCollectionMagicMetadata(
- collection,
- updatedPubMagicMetadata,
- );
- } catch (e) {
- log.error("change collection sort order failed", e);
- }
-};
-
export const changeCollectionOrder = async (
collection: Collection,
order: CollectionOrder,
) => updateCollectionOrder(await collection1To2(collection), order);
+export const changeCollectionSortOrder = async (
+ collection: Collection,
+ asc: boolean,
+) => updateCollectionSortOrder(await collection1To2(collection), asc);
+
export const changeCollectionSubType = async (
collection: Collection,
subType: CollectionSubType,
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index f4abfc48ee..0bcf7a92c9 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -718,10 +718,14 @@ const CollectionPrivateMagicMetadataData = z.looseObject({
*/
export interface CollectionPublicMagicMetadataData {
/**
+ * The ordering of the files within the collection.
+ *
+ * The default is desc ("Newest first").
+ *
* If true, then the files within the collection are sorted in ascending
* order of their time ("Oldest first").
*
- * The default is desc ("Newest first").
+ * To reset to the default, set this to false.
*/
asc?: boolean;
/**
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 239d871d5e..28441365b4 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -19,6 +19,7 @@ import {
type CollectionNewParticipantRole,
type CollectionOrder,
type CollectionPrivateMagicMetadataData,
+ type CollectionPublicMagicMetadataData,
type CollectionShareeMagicMetadataData,
type CollectionType,
type PublicURL,
@@ -472,8 +473,24 @@ export const updateCollectionVisibility = async (
export const updateCollectionOrder = async (
collection: Collection2,
order: CollectionOrder,
-) =>
- updateCollectionPrivateMagicMetadata(collection, { order })
+) => updateCollectionPrivateMagicMetadata(collection, { order });
+
+/**
+ * Change the sort order of the files with a collection on remote.
+ *
+ * Remote only, does not modify local state.
+ *
+ * This function works only for collections owned by the user.
+ *
+ * @param collection The collection whose file sort order we want to change.
+ *
+ * @param asc If true, then the files are sorted ascending (oldest first).
+ * Otherwise they are sorted descending (newest first).
+ */
+export const updateCollectionSortOrder = async (
+ collection: Collection2,
+ asc: boolean,
+) => updateCollectionPublicMagicMetadata(collection, { asc });
/**
* Update the private magic metadata contents of a collection on remote.
@@ -542,6 +559,43 @@ const putCollectionsMagicMetadata = async (
}),
);
+/**
+ * Update the public magic metadata contents of a collection on remote.
+ *
+ * Remote only, does not modify local state.
+ *
+ * This is a variant of {@link updateCollectionPrivateMagicMetadata} that works
+ * with the {@link pubMagicMetadata} of a collection.
+ */
+const updateCollectionPublicMagicMetadata = async (
+ { id, key, pubMagicMetadata }: Collection2,
+ updates: CollectionPublicMagicMetadataData,
+) =>
+ putCollectionsPublicMagicMetadata({
+ id,
+ magicMetadata: await encryptMagicMetadata(
+ createMagicMetadata(
+ { ...pubMagicMetadata?.data, ...updates },
+ pubMagicMetadata?.version,
+ ),
+ key,
+ ),
+ });
+
+/**
+ * Update the public magic metadata of a single collection on remote.
+ */
+const putCollectionsPublicMagicMetadata = async (
+ updateRequest: UpdateCollectionMagicMetadataRequest,
+) =>
+ ensureOk(
+ await fetch(await apiURL("/collections/public-magic-metadata"), {
+ method: "PUT",
+ headers: await authenticatedRequestHeaders(),
+ body: JSON.stringify(updateRequest),
+ }),
+ );
+
/**
* Update the per-sharee magic metadata contents of a collection on remote.
*