Skip to content

armgit / ente

Public Imported from GitHub
0

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

update mapping logic to use json file name

Abhinav3c9228a15bb4
diff --git a/apps/photos/src/services/upload/fileService.ts b/apps/photos/src/services/upload/fileService.ts
index c2bcd15f62..7a3ba16aba 100644
--- a/apps/photos/src/services/upload/fileService.ts
+++ b/apps/photos/src/services/upload/fileService.ts
@@ -15,7 +15,10 @@ import { addLogLine } from '@ente/shared/logging';
import { getFileNameSize } from '@ente/shared/logging/web';
import { encryptFiledata } from './encryptionService';
-import { extractMetadata, getMetadataJSONMapKey } from './metadataService';
+import {
+ extractMetadata,
+ getMetadataJSONMapKeyForFile,
+} from './metadataService';
import {
getFileStream,
getElectronFileStream,
@@ -80,7 +83,7 @@ export async function extractFileMetadata(
const originalName = getFileOriginalName(rawFile);
const googleMetadata =
parsedMetadataJSONMap.get(
- getMetadataJSONMapKey(collectionID, originalName)
+ getMetadataJSONMapKeyForFile(collectionID, originalName)
) ?? {};
const { metadata, publicMagicMetadata } = await extractMetadata(
diff --git a/apps/photos/src/services/upload/metadataService.ts b/apps/photos/src/services/upload/metadataService.ts
index 8ef875bb25..bcd3a6e393 100644
--- a/apps/photos/src/services/upload/metadataService.ts
+++ b/apps/photos/src/services/upload/metadataService.ts
@@ -22,11 +22,6 @@ import { Remote } from 'comlink';
import { DedicatedCryptoWorker } from '@ente/shared/crypto/internal/crypto.worker';
import { FilePublicMagicMetadataProps } from 'types/file';
-interface ParsedMetadataJSONWithTitle {
- title: string;
- parsedMetadataJSON: ParsedMetadataJSON;
-}
-
const NULL_PARSED_METADATA_JSON: ParsedMetadataJSON = {
creationTime: null,
modificationTime: null,
@@ -116,11 +111,20 @@ export async function getImageMetadata(
return imageMetadata;
}
-export const getMetadataJSONMapKey = (
+export const getMetadataJSONMapKeyForJSON = (
collectionID: number,
+ jsonFileName: string
+) => {
+ const title = jsonFileName.replace('.json', '');
+ return `${collectionID}-${title}`;
+};
- title: string
-) => `${collectionID}-${title}`;
+export const getMetadataJSONMapKeyForFile = (
+ collectionID: number,
+ fileName: string
+) => {
+ return `${collectionID}-${fileName}`;
+};
export async function parseMetadataJSON(receivedFile: File | ElectronFile) {
try {
@@ -134,11 +138,10 @@ export async function parseMetadataJSON(receivedFile: File | ElectronFile) {
const parsedMetadataJSON: ParsedMetadataJSON =
NULL_PARSED_METADATA_JSON;
- if (!metadataJSON || !metadataJSON['title']) {
+ if (!metadataJSON) {
return;
}
- const title = metadataJSON['title'];
if (
metadataJSON['photoTakenTime'] &&
metadataJSON['photoTakenTime']['timestamp']
@@ -177,7 +180,7 @@ export async function parseMetadataJSON(receivedFile: File | ElectronFile) {
parsedMetadataJSON.latitude = locationData.latitude;
parsedMetadataJSON.longitude = locationData.longitude;
}
- return { title, parsedMetadataJSON } as ParsedMetadataJSONWithTitle;
+ return parsedMetadataJSON;
} catch (e) {
logError(e, 'parseMetadataJSON failed');
// ignore
diff --git a/apps/photos/src/services/upload/uploadManager.ts b/apps/photos/src/services/upload/uploadManager.ts
index f8a02beb98..4edcaa2d11 100644
--- a/apps/photos/src/services/upload/uploadManager.ts
+++ b/apps/photos/src/services/upload/uploadManager.ts
@@ -2,7 +2,8 @@ import { getLocalFiles } from '../fileService';
import { SetFiles } from 'types/gallery';
import { sortFiles, decryptFile, getUserOwnedFiles } from 'utils/file';
import { logError } from '@ente/shared/sentry';
-import { getMetadataJSONMapKey, parseMetadataJSON } from './metadataService';
+import { parseMetadataJSON } from './metadataService';
+import { getMetadataJSONMapKeyForJSON } from './metadataService';
import {
areFileWithCollectionsSame,
segregateMetadataAndMediaFiles,
@@ -217,14 +218,13 @@ class UploadManager {
`parsing metadata json file ${getFileNameSize(file)}`
);
- const parsedMetadataJSONWithTitle = await parseMetadataJSON(
- file
- );
- if (parsedMetadataJSONWithTitle) {
- const { title, parsedMetadataJSON } =
- parsedMetadataJSONWithTitle;
+ const parsedMetadataJSON = await parseMetadataJSON(file);
+ if (parsedMetadataJSON) {
this.parsedMetadataJSONMap.set(
- getMetadataJSONMapKey(collectionID, title),
+ getMetadataJSONMapKeyForJSON(
+ collectionID,
+ file.name
+ ),
parsedMetadataJSON && { ...parsedMetadataJSON }
);
UIService.increaseFileUploaded();