Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor and add comments

Abhinav73069e2c61c1
diff --git a/apps/photos/src/services/upload/fileService.ts b/apps/photos/src/services/upload/fileService.ts
index 91fdb351dc..c62a14df70 100644
--- a/apps/photos/src/services/upload/fileService.ts
+++ b/apps/photos/src/services/upload/fileService.ts
@@ -8,6 +8,7 @@ import {
DataStream,
ElectronFile,
ExtractMetadataResult,
+ ParsedMetadataJSON,
} from 'types/upload';
import { logError } from '@ente/shared/sentry';
import { addLogLine } from '@ente/shared/logging';
@@ -15,9 +16,11 @@ import { getFileNameSize } from '@ente/shared/logging/web';
import { encryptFiledata } from './encryptionService';
import {
+ MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT,
+ NULL_PARSED_METADATA_JSON,
extractMetadata,
getClippedMetadataJSONMapKeyForFile,
- getFullMetadataJSONMapKeyForFile,
+ getMetadataJSONMapKeyForFile,
} from './metadataService';
import {
getFileStream,
@@ -78,14 +81,14 @@ export async function extractFileMetadata(
fileTypeInfo: FileTypeInfo,
rawFile: File | ElectronFile
): Promise<ExtractMetadataResult> {
- const googleMetadata =
- parsedMetadataJSONMap.get(
- getFullMetadataJSONMapKeyForFile(collectionID, rawFile.name)
- ) ??
- parsedMetadataJSONMap.get(
- getClippedMetadataJSONMapKeyForFile(collectionID, rawFile.name)
- ) ??
- {};
+ let key = getMetadataJSONMapKeyForFile(collectionID, rawFile.name);
+ let googleMetadata: ParsedMetadataJSON =
+ parsedMetadataJSONMap.get(key) ?? NULL_PARSED_METADATA_JSON;
+
+ if (!googleMetadata && key.length > MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT) {
+ key = getClippedMetadataJSONMapKeyForFile(collectionID, rawFile.name);
+ googleMetadata = parsedMetadataJSONMap.get(key);
+ }
const { metadata, publicMagicMetadata } = await extractMetadata(
worker,
diff --git a/apps/photos/src/services/upload/metadataService.ts b/apps/photos/src/services/upload/metadataService.ts
index d310a0b7e4..5f7cb42eab 100644
--- a/apps/photos/src/services/upload/metadataService.ts
+++ b/apps/photos/src/services/upload/metadataService.ts
@@ -23,7 +23,7 @@ import { DedicatedCryptoWorker } from '@ente/shared/crypto/internal/crypto.worke
import { FilePublicMagicMetadataProps } from 'types/file';
import { splitFilenameAndExtension } from 'utils/file';
-const NULL_PARSED_METADATA_JSON: ParsedMetadataJSON = {
+export const NULL_PARSED_METADATA_JSON: ParsedMetadataJSON = {
creationTime: null,
modificationTime: null,
...NULL_LOCATION,
@@ -47,6 +47,8 @@ const EXIF_TAGS_NEEDED = [
'MetadataDate',
];
+export const MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT = 46;
+
export async function extractMetadata(
worker: Remote<DedicatedCryptoWorker>,
receivedFile: File | ElectronFile,
@@ -129,14 +131,19 @@ export const getMetadataJSONMapKeyForJSON = (
return `${collectionID}-${title}`;
};
+// if the file name is greater than MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT(46) , then google photos clips the file name
+// so we need to use the clipped file name to get the metadataJSON file
export const getClippedMetadataJSONMapKeyForFile = (
collectionID: number,
fileName: string
) => {
- return `${collectionID}-${fileName.slice(0, 46)}`;
+ return `${collectionID}-${fileName.slice(
+ 0,
+ MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT
+ )}`;
};
-export const getFullMetadataJSONMapKeyForFile = (
+export const getMetadataJSONMapKeyForFile = (
collectionID: number,
fileName: string
) => {
diff --git a/apps/photos/tests/upload.test.ts b/apps/photos/tests/upload.test.ts
index 75e2bfa0bc..376cb5c6dc 100644
--- a/apps/photos/tests/upload.test.ts
+++ b/apps/photos/tests/upload.test.ts
@@ -6,7 +6,7 @@ import { FILE_TYPE } from 'constants/file';
import { tryToParseDateTime } from '@ente/shared/time';
import {
getClippedMetadataJSONMapKeyForFile,
- getFullMetadataJSONMapKeyForFile,
+ getMetadataJSONMapKeyForFile,
getMetadataJSONMapKeyForJSON,
} from 'services/upload/metadataService';
@@ -395,10 +395,7 @@ function mappingFileAndJSONFileCheck() {
0,
jsonFilename
);
- let fileNameGeneratedKey = getFullMetadataJSONMapKeyForFile(
- 0,
- filename
- );
+ let fileNameGeneratedKey = getMetadataJSONMapKeyForFile(0, filename);
if (fileNameGeneratedKey !== jsonFileNameGeneratedKey) {
fileNameGeneratedKey = getClippedMetadataJSONMapKeyForFile(
0,