Skip to content

armgit / ente

Public Imported from GitHub
0

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

added-comments

Aswin Asokb73520e7f845
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx
index a187523a8c..2a72decdab 100644
--- a/web/apps/photos/src/components/Upload.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -1268,6 +1268,16 @@ const deriveImportSuggestionFromPaths = (
};
};
+/**
+ *
+ * @param uploadType
+ * @param uploadItemAndPaths
+ * @returns
+ *
+ * rootFolderName: The name of root folder, if there exist a metadata.json in the
+ * same directory which has a valid title we will be using that else will
+ * fallback to the directory foldername.
+ */
const deriveImportSuggestion = async (
uploadType: UploadType | undefined,
uploadItemAndPaths: UploadItemAndPath[],
@@ -1276,10 +1286,12 @@ const deriveImportSuggestion = async (
uploadType,
uploadItemAndPaths.map(([, path]) => path),
);
+
const albumMetadataJSON = takeoutAlbumMetadataJSONItemForFolder(
uploadItemAndPaths,
suggestion.rootFolderPath,
);
+
const albumName = albumMetadataJSON
? await tryParseTakeoutAlbumNameMetadataJSON(albumMetadataJSON)
: undefined;
diff --git a/web/packages/gallery/services/upload/index.ts b/web/packages/gallery/services/upload/index.ts
index 543deeeffa..f64423414e 100644
--- a/web/packages/gallery/services/upload/index.ts
+++ b/web/packages/gallery/services/upload/index.ts
@@ -189,6 +189,13 @@ export const uploadPathPrefix = (pathOrName: string) => {
export type UploadItemAndPath = [UploadItem, string];
+/**
+ * Build a lookup of album-level Takeout `metadata.json` files by their
+ * containing folder path.
+ *
+ * This only indexes files named exactly `metadata.json`. If multiple entries
+ * exist for the same folder, the first one in the upload list is retained.
+ */
const takeoutAlbumMetadataJSONItemsByFolderPath = (
uploadItemAndPaths: UploadItemAndPath[],
) => {
@@ -202,6 +209,14 @@ const takeoutAlbumMetadataJSONItemsByFolderPath = (
return result;
};
+/**
+ * Return the album-level Takeout `metadata.json` upload item for the given
+ * folder path, if one was included in the upload list.
+ *
+ * The `folderPath` must match the metadata file's containing folder exactly.
+ * The returned item is not parsed here; callers parse its `title` when they
+ * need an album-name suggestion.
+ */
export const takeoutAlbumMetadataJSONItemForFolder = (
uploadItemAndPaths: UploadItemAndPath[],
folderPath: string,
diff --git a/web/packages/gallery/services/upload/metadata-json.ts b/web/packages/gallery/services/upload/metadata-json.ts
index f0b76985f3..17b348e865 100644
--- a/web/packages/gallery/services/upload/metadata-json.ts
+++ b/web/packages/gallery/services/upload/metadata-json.ts
@@ -262,6 +262,15 @@ const parseMetadataJSONText = (text: string) => {
return parsedMetadataJSON;
};
+/**
+ *
+ * @param text
+ * @returns metadata.json.title which is the album name
+ *
+ * This function receives the contents of the metadata.json
+ * and check whether it's a valid object and if so then
+ * tries to parse the title and return it.
+ */
const parseAlbumNameMetadataJSONText = (text: string) => {
const metadataJSON_ = JSON.parse(text) as unknown;
if (typeof metadataJSON_ != "object") return undefined;