|
@@ -495,7 +495,7 @@ const readFOPFileTypeInfoAndSize = async (
|
|
const readEntireStream = async (stream: ReadableStream) =>
|
|
const readEntireStream = async (stream: ReadableStream) =>
|
|
new Uint8Array(await new Response(stream).arrayBuffer());
|
|
new Uint8Array(await new Response(stream).arrayBuffer());
|
|
|
|
|
|
-interface ExtractMetadataResult {
|
|
|
|
|
|
+interface ExtractAssetMetadataResult {
|
|
metadata: Metadata;
|
|
metadata: Metadata;
|
|
publicMagicMetadata: FilePublicMagicMetadataProps;
|
|
publicMagicMetadata: FilePublicMagicMetadataProps;
|
|
}
|
|
}
|
|
@@ -510,50 +510,45 @@ const extractAssetMetadata = async (
|
|
collectionID: number,
|
|
collectionID: number,
|
|
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
|
|
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
|
|
worker: Remote<DedicatedCryptoWorker>,
|
|
worker: Remote<DedicatedCryptoWorker>,
|
|
-): Promise<ExtractMetadataResult> => {
|
|
|
|
- return isLivePhoto
|
|
|
|
|
|
+): Promise<ExtractAssetMetadataResult> =>
|
|
|
|
+ isLivePhoto
|
|
? await extractLivePhotoMetadata(
|
|
? await extractLivePhotoMetadata(
|
|
- worker,
|
|
|
|
- parsedMetadataJSONMap,
|
|
|
|
- collectionID,
|
|
|
|
- fileTypeInfo,
|
|
|
|
livePhotoAssets,
|
|
livePhotoAssets,
|
|
- )
|
|
|
|
- : await extractFileMetadata(
|
|
|
|
- worker,
|
|
|
|
- parsedMetadataJSONMap,
|
|
|
|
- collectionID,
|
|
|
|
fileTypeInfo,
|
|
fileTypeInfo,
|
|
|
|
+ collectionID,
|
|
|
|
+ parsedMetadataJSONMap,
|
|
|
|
+ worker,
|
|
|
|
+ )
|
|
|
|
+ : await extractImageOrVideoMetadata(
|
|
file,
|
|
file,
|
|
|
|
+ fileTypeInfo,
|
|
|
|
+ collectionID,
|
|
|
|
+ parsedMetadataJSONMap,
|
|
|
|
+ worker,
|
|
);
|
|
);
|
|
-};
|
|
|
|
|
|
|
|
-async function extractLivePhotoMetadata(
|
|
|
|
- worker: Remote<DedicatedCryptoWorker>,
|
|
|
|
- parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
|
|
|
|
- collectionID: number,
|
|
|
|
- fileTypeInfo: FileTypeInfo,
|
|
|
|
|
|
+const extractLivePhotoMetadata = async (
|
|
livePhotoAssets: LivePhotoAssets2,
|
|
livePhotoAssets: LivePhotoAssets2,
|
|
-): Promise<ExtractMetadataResult> {
|
|
|
|
|
|
+ fileTypeInfo: FileTypeInfo,
|
|
|
|
+ collectionID: number,
|
|
|
|
+ parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
|
|
|
|
+ worker: Remote<DedicatedCryptoWorker>,
|
|
|
|
+) => {
|
|
const imageFileTypeInfo: FileTypeInfo = {
|
|
const imageFileTypeInfo: FileTypeInfo = {
|
|
fileType: FILE_TYPE.IMAGE,
|
|
fileType: FILE_TYPE.IMAGE,
|
|
extension: fileTypeInfo.imageType,
|
|
extension: fileTypeInfo.imageType,
|
|
};
|
|
};
|
|
- const {
|
|
|
|
- metadata: imageMetadata,
|
|
|
|
- publicMagicMetadata: imagePublicMagicMetadata,
|
|
|
|
- } = await extractFileMetadata(
|
|
|
|
- worker,
|
|
|
|
- parsedMetadataJSONMap,
|
|
|
|
- collectionID,
|
|
|
|
- imageFileTypeInfo,
|
|
|
|
- livePhotoAssets.image,
|
|
|
|
- );
|
|
|
|
- const videoHash = await getFileHash(
|
|
|
|
- worker,
|
|
|
|
- /* TODO(MR): ElectronFile changes */
|
|
|
|
- livePhotoAssets.video as File | ElectronFile,
|
|
|
|
- );
|
|
|
|
|
|
+ const { metadata: imageMetadata, publicMagicMetadata } =
|
|
|
|
+ await extractImageOrVideoMetadata(
|
|
|
|
+ livePhotoAssets.image,
|
|
|
|
+ imageFileTypeInfo,
|
|
|
|
+ collectionID,
|
|
|
|
+ parsedMetadataJSONMap,
|
|
|
|
+ worker,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const videoHash = await computeHash(livePhotoAssets.video, worker);
|
|
|
|
+
|
|
return {
|
|
return {
|
|
metadata: {
|
|
metadata: {
|
|
...imageMetadata,
|
|
...imageMetadata,
|
|
@@ -563,20 +558,20 @@ async function extractLivePhotoMetadata(
|
|
videoHash: videoHash,
|
|
videoHash: videoHash,
|
|
hash: undefined,
|
|
hash: undefined,
|
|
},
|
|
},
|
|
- publicMagicMetadata: imagePublicMagicMetadata,
|
|
|
|
|
|
+ publicMagicMetadata,
|
|
};
|
|
};
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
-async function extractFileMetadata(
|
|
|
|
- worker: Remote<DedicatedCryptoWorker>,
|
|
|
|
- parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
|
|
|
|
- collectionID: number,
|
|
|
|
- fileTypeInfo: FileTypeInfo,
|
|
|
|
|
|
+const extractImageOrVideoMetadata = async (
|
|
rawFile: File | ElectronFile | string,
|
|
rawFile: File | ElectronFile | string,
|
|
-): Promise<ExtractMetadataResult> {
|
|
|
|
|
|
+ fileTypeInfo: FileTypeInfo,
|
|
|
|
+ collectionID: number,
|
|
|
|
+ parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
|
|
|
|
+ worker: Remote<DedicatedCryptoWorker>,
|
|
|
|
+) => {
|
|
const rawFileName = getFileName(rawFile);
|
|
const rawFileName = getFileName(rawFile);
|
|
let key = getMetadataJSONMapKeyForFile(collectionID, rawFileName);
|
|
let key = getMetadataJSONMapKeyForFile(collectionID, rawFileName);
|
|
- let googleMetadata: ParsedMetadataJSON = parsedMetadataJSONMap.get(key);
|
|
|
|
|
|
+ let googleMetadata = parsedMetadataJSONMap.get(key);
|
|
|
|
|
|
if (!googleMetadata && key.length > MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT) {
|
|
if (!googleMetadata && key.length > MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT) {
|
|
key = getClippedMetadataJSONMapKeyForFile(collectionID, rawFileName);
|
|
key = getClippedMetadataJSONMapKeyForFile(collectionID, rawFileName);
|
|
@@ -584,10 +579,10 @@ async function extractFileMetadata(
|
|
}
|
|
}
|
|
|
|
|
|
const { metadata, publicMagicMetadata } = await extractMetadata(
|
|
const { metadata, publicMagicMetadata } = await extractMetadata(
|
|
- worker,
|
|
|
|
/* TODO(MR): ElectronFile changes */
|
|
/* TODO(MR): ElectronFile changes */
|
|
rawFile as File | ElectronFile,
|
|
rawFile as File | ElectronFile,
|
|
fileTypeInfo,
|
|
fileTypeInfo,
|
|
|
|
+ worker,
|
|
);
|
|
);
|
|
|
|
|
|
for (const [key, value] of Object.entries(googleMetadata ?? {})) {
|
|
for (const [key, value] of Object.entries(googleMetadata ?? {})) {
|
|
@@ -597,7 +592,7 @@ async function extractFileMetadata(
|
|
metadata[key] = value;
|
|
metadata[key] = value;
|
|
}
|
|
}
|
|
return { metadata, publicMagicMetadata };
|
|
return { metadata, publicMagicMetadata };
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
const NULL_EXTRACTED_METADATA: ParsedExtractedMetadata = {
|
|
const NULL_EXTRACTED_METADATA: ParsedExtractedMetadata = {
|
|
location: NULL_LOCATION,
|
|
location: NULL_LOCATION,
|
|
@@ -606,18 +601,18 @@ const NULL_EXTRACTED_METADATA: ParsedExtractedMetadata = {
|
|
height: null,
|
|
height: null,
|
|
};
|
|
};
|
|
|
|
|
|
-async function extractMetadata(
|
|
|
|
- worker: Remote<DedicatedCryptoWorker>,
|
|
|
|
|
|
+const extractMetadata = async (
|
|
receivedFile: File | ElectronFile,
|
|
receivedFile: File | ElectronFile,
|
|
fileTypeInfo: FileTypeInfo,
|
|
fileTypeInfo: FileTypeInfo,
|
|
-): Promise<ExtractMetadataResult> {
|
|
|
|
|
|
+ worker: Remote<DedicatedCryptoWorker>,
|
|
|
|
+) => {
|
|
let extractedMetadata: ParsedExtractedMetadata = NULL_EXTRACTED_METADATA;
|
|
let extractedMetadata: ParsedExtractedMetadata = NULL_EXTRACTED_METADATA;
|
|
if (fileTypeInfo.fileType === FILE_TYPE.IMAGE) {
|
|
if (fileTypeInfo.fileType === FILE_TYPE.IMAGE) {
|
|
extractedMetadata = await getImageMetadata(receivedFile, fileTypeInfo);
|
|
extractedMetadata = await getImageMetadata(receivedFile, fileTypeInfo);
|
|
} else if (fileTypeInfo.fileType === FILE_TYPE.VIDEO) {
|
|
} else if (fileTypeInfo.fileType === FILE_TYPE.VIDEO) {
|
|
extractedMetadata = await getVideoMetadata(receivedFile);
|
|
extractedMetadata = await getVideoMetadata(receivedFile);
|
|
}
|
|
}
|
|
- const hash = await getFileHash(worker, receivedFile);
|
|
|
|
|
|
+ const hash = await computeHash(receivedFile, worker);
|
|
|
|
|
|
const metadata: Metadata = {
|
|
const metadata: Metadata = {
|
|
title: receivedFile.name,
|
|
title: receivedFile.name,
|
|
@@ -679,10 +674,11 @@ async function getVideoMetadata(file: File | ElectronFile) {
|
|
return videoMetadata;
|
|
return videoMetadata;
|
|
}
|
|
}
|
|
|
|
|
|
-async function getFileHash(
|
|
|
|
|
|
+const computeHash = async (
|
|
|
|
+ fileOrPath: File | string,
|
|
worker: Remote<DedicatedCryptoWorker>,
|
|
worker: Remote<DedicatedCryptoWorker>,
|
|
- file: File | ElectronFile,
|
|
|
|
-) {
|
|
|
|
|
|
+) => {
|
|
|
|
+ const file = fileOrPath as File; /* TODO(MR): ElectronFile changes */
|
|
try {
|
|
try {
|
|
log.info(`getFileHash called for ${getFileNameSize(file)}`);
|
|
log.info(`getFileHash called for ${getFileNameSize(file)}`);
|
|
let filedata: DataStream;
|
|
let filedata: DataStream;
|
|
@@ -717,7 +713,7 @@ async function getFileHash(
|
|
log.error("getFileHash failed", e);
|
|
log.error("getFileHash failed", e);
|
|
log.info(`file hashing failed ${getFileNameSize(file)} ,${e.message} `);
|
|
log.info(`file hashing failed ${getFileNameSize(file)} ,${e.message} `);
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
const readAsset = async (
|
|
const readAsset = async (
|
|
fileTypeInfo: FileTypeInfo,
|
|
fileTypeInfo: FileTypeInfo,
|