[web] Parse description from Google Takeout metadata JSON (#3540)

Fixes https://github.com/ente-io/ente/issues/3537
This commit is contained in:
Manav Rathi
2024-09-30 17:10:43 +05:30
committed by GitHub
4 changed files with 30 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
## v1.7.6 (Unreleased)
- Parse description from Google Takeout metadata JSON.
- .
## v1.7.5

View File

@@ -19,6 +19,7 @@ export interface ParsedMetadataJSON {
creationTime?: number;
modificationTime?: number;
location?: Location;
description?: string;
}
export const MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT = 46;
@@ -126,6 +127,10 @@ const parseMetadataJSONText = (text: string) => {
parseGTLocation(metadataJSON["geoData"]) ??
parseGTLocation(metadataJSON["geoDataExif"]);
parsedMetadataJSON.description = parseGTNonEmptyString(
metadataJSON["description"],
);
return parsedMetadataJSON;
};
@@ -172,6 +177,13 @@ const parseGTLocation = (o: unknown): Location | undefined => {
return undefined;
};
/**
* Parse a string from a field in a Google Takeout JSON, treating empty strings
* as undefined.
*/
const parseGTNonEmptyString = (o: unknown): string | undefined =>
o && typeof o == "string" ? o : undefined;
/**
* Return the matching entry (if any) from {@link parsedMetadataJSONMap} for the
* {@link fileName} and {@link collectionID} combination.

View File

@@ -1014,6 +1014,11 @@ const extractImageOrVideoMetadata = async (
if (h) publicMagicMetadata.h = ensureInteger(h);
}
const caption = parsedMetadataJSON?.description;
if (caption) {
publicMagicMetadata.caption = caption;
}
return { metadata, publicMagicMetadata };
};

View File

@@ -144,10 +144,22 @@ export interface FilePublicMagicMetadataProps {
* Epoch microseconds.
*/
editedTime?: number;
/**
* Edited name of the {@link EnteFile}.
*
* If the user edits the name of the file within Ente, then the edits are
* saved in this field.
*/
editedName?: string;
/**
* A arbitrary textual caption / description that the user has attached to
* the {@link EnteFile}.
*/
caption?: string;
uploaderName?: string;
/** Width of the image / video, in pixels. */
w?: number;
/** Height of the image / video, in pixels. */
h?: number;
}