This commit is contained in:
Manav Rathi 2024-04-24 10:13:03 +05:30
parent 48bace50df
commit 9103dadc6f
No known key found for this signature in database
2 changed files with 17 additions and 15 deletions

View file

@ -74,9 +74,10 @@ function getFileOriginalName(fileName: string) {
return originalName;
}
export async function parseMetadataJSON(
/** Try to parse the contents of a metadata JSON file in a Google Takeout. */
export const tryParseTakeoutMetadataJSON = async (
receivedFile: File | ElectronFile | string,
) {
): Promise<ParsedMetadataJSON | undefined> => {
try {
let text: string;
if (typeof receivedFile == "string") {
@ -93,8 +94,8 @@ export async function parseMetadataJSON(
return parseMetadataJSONText(text);
} catch (e) {
log.error("parseMetadataJSON failed", e);
// ignore
log.error("Failed to parse takeout metadata JSON", e);
return undefined;
}
}
@ -105,13 +106,13 @@ const NULL_PARSED_METADATA_JSON: ParsedMetadataJSON = {
...NULL_LOCATION,
};
export async function parseMetadataJSONText(text: string) {
const parseMetadataJSONText = (text: string) => {
const metadataJSON: object = JSON.parse(text);
if (!metadataJSON) {
return undefined;
}
const parsedMetadataJSON: ParsedMetadataJSON = NULL_PARSED_METADATA_JSON;
if (!metadataJSON) {
return;
}
if (
metadataJSON["photoTakenTime"] &&

View file

@ -43,12 +43,12 @@ import {
segregateMetadataAndMediaFiles2,
} from "utils/upload";
import { getLocalFiles } from "../fileService";
import { clusterLivePhotoFiles } from "./metadataService";
import {
clusterLivePhotoFiles,
getMetadataJSONMapKeyForJSON,
parseMetadataJSON,
} from "./metadataService";
import type { ParsedMetadataJSON } from "./takeout";
tryParseTakeoutMetadataJSON,
type ParsedMetadataJSON,
} from "./takeout";
import uploadCancelService from "./uploadCancelService";
import UploadService, {
assetName,
@ -523,11 +523,12 @@ class UploadManager {
log.info(`parsing metadata json file ${name}`);
const parsedMetadataJSON = await parseMetadataJSON(file);
if (parsedMetadataJSON) {
const metadataJSON =
await tryParseTakeoutMetadataJSON(file);
if (metadataJSON) {
this.parsedMetadataJSONMap.set(
getMetadataJSONMapKeyForJSON(collectionID, name),
parsedMetadataJSON && { ...parsedMetadataJSON },
metadataJSON && { ...metadataJSON },
);
this.uiService.increaseFileUploaded();
}