diff --git a/web/apps/photos/src/services/upload/metadataService.ts b/web/apps/photos/src/services/upload/metadataService.ts index ad391eb45..e4f4c348b 100644 --- a/web/apps/photos/src/services/upload/metadataService.ts +++ b/web/apps/photos/src/services/upload/metadataService.ts @@ -61,7 +61,63 @@ export interface ExtractMetadataResult { publicMagicMetadata: FilePublicMagicMetadataProps; } -export async function extractMetadata( +export const extractAssetMetadata = async ( + worker: Remote, + parsedMetadataJSONMap: Map, + { isLivePhoto, file, livePhotoAssets }: UploadAsset2, + collectionID: number, + fileTypeInfo: FileTypeInfo, +): Promise => { + return isLivePhoto + ? await extractLivePhotoMetadata( + worker, + parsedMetadataJSONMap, + collectionID, + fileTypeInfo, + livePhotoAssets, + ) + : await extractFileMetadata( + worker, + parsedMetadataJSONMap, + collectionID, + fileTypeInfo, + file, + ); +}; + +async function extractFileMetadata( + worker: Remote, + parsedMetadataJSONMap: Map, + collectionID: number, + fileTypeInfo: FileTypeInfo, + rawFile: File | ElectronFile | string, +): Promise { + const rawFileName = getFileName(rawFile); + let key = getMetadataJSONMapKeyForFile(collectionID, rawFileName); + let googleMetadata: ParsedMetadataJSON = parsedMetadataJSONMap.get(key); + + if (!googleMetadata && key.length > MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT) { + key = getClippedMetadataJSONMapKeyForFile(collectionID, rawFileName); + googleMetadata = parsedMetadataJSONMap.get(key); + } + + const { metadata, publicMagicMetadata } = await extractMetadata( + worker, + /* TODO(MR): ElectronFile changes */ + rawFile as File | ElectronFile, + fileTypeInfo, + ); + + for (const [key, value] of Object.entries(googleMetadata ?? {})) { + if (!value) { + continue; + } + metadata[key] = value; + } + return { metadata, publicMagicMetadata }; +} + +async function extractMetadata( worker: Remote, receivedFile: File | ElectronFile, fileTypeInfo: FileTypeInfo, @@ -182,62 +238,6 @@ async function getVideoMetadata(file: File | ElectronFile) { return videoMetadata; } -export const extractAssetMetadata = async ( - worker: Remote, - parsedMetadataJSONMap: Map, - { isLivePhoto, file, livePhotoAssets }: UploadAsset2, - collectionID: number, - fileTypeInfo: FileTypeInfo, -): Promise => { - return isLivePhoto - ? await extractLivePhotoMetadata( - worker, - parsedMetadataJSONMap, - collectionID, - fileTypeInfo, - livePhotoAssets, - ) - : await extractFileMetadata( - worker, - parsedMetadataJSONMap, - collectionID, - fileTypeInfo, - file, - ); -}; - -async function extractFileMetadata( - worker: Remote, - parsedMetadataJSONMap: Map, - collectionID: number, - fileTypeInfo: FileTypeInfo, - rawFile: File | ElectronFile | string, -): Promise { - const rawFileName = getFileName(rawFile); - let key = getMetadataJSONMapKeyForFile(collectionID, rawFileName); - let googleMetadata: ParsedMetadataJSON = parsedMetadataJSONMap.get(key); - - if (!googleMetadata && key.length > MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT) { - key = getClippedMetadataJSONMapKeyForFile(collectionID, rawFileName); - googleMetadata = parsedMetadataJSONMap.get(key); - } - - const { metadata, publicMagicMetadata } = await extractMetadata( - worker, - /* TODO(MR): ElectronFile changes */ - rawFile as File | ElectronFile, - fileTypeInfo, - ); - - for (const [key, value] of Object.entries(googleMetadata ?? {})) { - if (!value) { - continue; - } - metadata[key] = value; - } - return { metadata, publicMagicMetadata }; -} - async function extractLivePhotoMetadata( worker: Remote, parsedMetadataJSONMap: Map,