This commit is contained in:
Manav Rathi 2024-04-24 11:32:31 +05:30
parent e490f194e7
commit feb59b00d2
No known key found for this signature in database
2 changed files with 21 additions and 26 deletions

View file

@ -13,11 +13,9 @@ import { FILE_TYPE } from "constants/file";
import { FILE_READER_CHUNK_SIZE, NULL_LOCATION } from "constants/upload";
import * as ffmpegService from "services/ffmpeg";
import { getElectronFileStream, getFileStream } from "services/readerService";
import { getFileType } from "services/typeDetectionService";
import { FilePublicMagicMetadataProps } from "types/file";
import {
FileTypeInfo,
LivePhotoAssets,
Metadata,
ParsedExtractedMetadata,
type DataStream,
@ -95,7 +93,7 @@ export async function extractMetadata(
return { metadata, publicMagicMetadata };
}
export async function getImageMetadata(
async function getImageMetadata(
receivedFile: File | ElectronFile,
fileTypeInfo: FileTypeInfo,
): Promise<ParsedExtractedMetadata> {
@ -129,7 +127,7 @@ export async function getImageMetadata(
}
// tries to extract date from file name if available else returns null
export function extractDateFromFileName(filename: string): number {
function extractDateFromFileName(filename: string): number {
try {
filename = filename.trim();
let parsedDate: Date;
@ -184,19 +182,6 @@ async function getVideoMetadata(file: File | ElectronFile) {
return videoMetadata;
}
export async function getLivePhotoFileType(
livePhotoAssets: LivePhotoAssets,
): Promise<FileTypeInfo> {
const imageFileTypeInfo = await getFileType(livePhotoAssets.image);
const videoFileTypeInfo = await getFileType(livePhotoAssets.video);
return {
fileType: FILE_TYPE.LIVE_PHOTO,
exactType: `${imageFileTypeInfo.exactType}+${videoFileTypeInfo.exactType}`,
imageType: imageFileTypeInfo.exactType,
videoType: videoFileTypeInfo.exactType,
};
}
export const extractAssetMetadata = async (
worker: Remote<DedicatedCryptoWorker>,
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
@ -331,7 +316,3 @@ async function getFileHash(
log.info(`file hashing failed ${getFileNameSize(file)} ,${e.message} `);
}
}
export function getLivePhotoSize(livePhotoAssets: LivePhotoAssets) {
return livePhotoAssets.image.size + livePhotoAssets.video.size;
}

View file

@ -37,6 +37,7 @@ import {
isDataStream,
type DataStream,
type FileWithCollection2,
type LivePhotoAssets,
type LivePhotoAssets2,
type Metadata,
type UploadAsset2,
@ -50,11 +51,7 @@ import { hasFileHash } from "utils/upload";
import * as convert from "xml-js";
import { getFileStream } from "../readerService";
import { getFileType } from "../typeDetectionService";
import {
extractAssetMetadata,
getLivePhotoFileType,
getLivePhotoSize,
} from "./metadataService";
import { extractAssetMetadata, getLivePhotoFileType } from "./metadataService";
import publicUploadHttpClient from "./publicUploadHttpClient";
import type { ParsedMetadataJSON } from "./takeout";
import {
@ -330,6 +327,10 @@ const getAssetSize = ({ isLivePhoto, file, livePhotoAssets }: UploadAsset) => {
return isLivePhoto ? getLivePhotoSize(livePhotoAssets) : getFileSize(file);
};
const getLivePhotoSize = (livePhotoAssets: LivePhotoAssets) => {
return livePhotoAssets.image.size + livePhotoAssets.video.size;
};
const getAssetFileType = ({
isLivePhoto,
file,
@ -340,6 +341,19 @@ const getAssetFileType = ({
: getFileType(file);
};
const getLivePhotoFileType = async (
livePhotoAssets: LivePhotoAssets,
): Promise<FileTypeInfo> => {
const imageFileTypeInfo = await getFileType(livePhotoAssets.image);
const videoFileTypeInfo = await getFileType(livePhotoAssets.video);
return {
fileType: FILE_TYPE.LIVE_PHOTO,
exactType: `${imageFileTypeInfo.exactType}+${videoFileTypeInfo.exactType}`,
imageType: imageFileTypeInfo.exactType,
videoType: videoFileTypeInfo.exactType,
};
};
const readAsset = async (
fileTypeInfo: FileTypeInfo,
{ isLivePhoto, file, livePhotoAssets }: UploadAsset2,