diff --git a/web/apps/photos/src/services/upload/metadataService.ts b/web/apps/photos/src/services/upload/metadataService.ts index 367d79bba..aa0b474b2 100644 --- a/web/apps/photos/src/services/upload/metadataService.ts +++ b/web/apps/photos/src/services/upload/metadataService.ts @@ -29,6 +29,7 @@ import { type FileWithCollection, type FileWithCollection2, type LivePhotoAssets2, + type UploadAsset2, } from "types/upload"; import { getFileTypeFromExtensionForLivePhotoClustering } from "utils/file/livePhoto"; import { getEXIFLocation, getEXIFTime, getParsedExifData } from "./exifService"; @@ -349,7 +350,63 @@ export async function getLivePhotoFileType( }; } -export async function extractLivePhotoMetadata( +export const extractAssetMetadata = async ( + worker: Remote, + parsedMetadataJSONMap: ParsedMetadataJSONMap, + { 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: ParsedMetadataJSONMap, + 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: ParsedMetadataJSONMap, collectionID: number, diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts index b49b2937e..2bed3d933 100644 --- a/web/apps/photos/src/services/upload/uploadService.ts +++ b/web/apps/photos/src/services/upload/uploadService.ts @@ -56,14 +56,10 @@ import { findMatchingExistingFiles } from "utils/upload"; import { getFileStream } from "../readerService"; import { getFileType } from "../typeDetectionService"; import { - MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT, - extractLivePhotoMetadata, - extractMetadata, - getClippedMetadataJSONMapKeyForFile, + extractAssetMetadata, getLivePhotoFileType, getLivePhotoName, getLivePhotoSize, - getMetadataJSONMapKeyForFile, } from "./metadataService"; import { uploadStreamUsingMultipart } from "./multiPartUploadService"; import publicUploadHttpClient from "./publicUploadHttpClient"; @@ -145,25 +141,17 @@ class UploadService { async extractAssetMetadata( worker: Remote, - { isLivePhoto, file, livePhotoAssets }: UploadAsset2, + uploadAsset: UploadAsset2, collectionID: number, fileTypeInfo: FileTypeInfo, ): Promise { - return isLivePhoto - ? extractLivePhotoMetadata( - worker, - this.parsedMetadataJSONMap, - collectionID, - fileTypeInfo, - livePhotoAssets, - ) - : await extractFileMetadata( - worker, - this.parsedMetadataJSONMap, - collectionID, - fileTypeInfo, - file, - ); + return await extractAssetMetadata( + worker, + this.parsedMetadataJSONMap, + uploadAsset, + collectionID, + fileTypeInfo, + ); } async encryptAsset( @@ -621,38 +609,6 @@ const readLivePhoto = async ( }; }; -export async function extractFileMetadata( - worker: Remote, - parsedMetadataJSONMap: ParsedMetadataJSONMap, - 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 encryptFile( worker: Remote, file: FileWithMetadata, @@ -843,7 +799,7 @@ export async function uploader( } log.info(`reading asset ${fileNameSize}`); - const file = readAsset(fileTypeInfo, uploadAsset); + const file = await readAsset(fileTypeInfo, uploadAsset); if (file.hasStaticThumbnail) { metadata.hasStaticThumbnail = true;