This commit is contained in:
Manav Rathi 2024-04-23 15:48:52 +05:30
parent 91afe68111
commit 3a93a7a956
No known key found for this signature in database
3 changed files with 25 additions and 17 deletions

View file

@ -435,7 +435,7 @@ async function extractLivePhotoMetadata(
return {
metadata: {
...imageMetadata,
title: getLivePhotoName(livePhotoAssets),
title: getFileName(livePhotoAssets.image),
fileType: FILE_TYPE.LIVE_PHOTO,
imageHash: imageMetadata.hash,
videoHash: videoHash,
@ -449,9 +449,6 @@ export function getLivePhotoSize(livePhotoAssets: LivePhotoAssets) {
return livePhotoAssets.image.size + livePhotoAssets.video.size;
}
export const getLivePhotoName = ({ image }: LivePhotoAssets2) =>
typeof image == "string" ? basename(image) : image.name;
export async function clusterLivePhotoFiles(mediaFiles: FileWithCollection2[]) {
try {
const analysedMediaFiles: FileWithCollection2[] = [];

View file

@ -40,7 +40,12 @@ import {
} from "./metadataService";
import { default as UIService, default as uiService } from "./uiService";
import uploadCancelService from "./uploadCancelService";
import UploadService, { getFileName, uploader } from "./uploadService";
import UploadService, {
assetName,
getAssetName,
getFileName,
uploader,
} from "./uploadService";
const MAX_CONCURRENT_UPLOADS = 4;
@ -132,7 +137,7 @@ class UploadManager {
new Map<number, string>(
filesWithCollectionToUploadIn.map((mediaFile) => [
mediaFile.localID,
UploadService.getAssetName(mediaFile),
getAssetName(mediaFile),
]),
),
);
@ -164,7 +169,7 @@ class UploadManager {
new Map<number, string>(
analysedMediaFiles.map((mediaFile) => [
mediaFile.localID,
UploadService.getAssetName(mediaFile),
assetName(mediaFile),
]),
),
);
@ -223,7 +228,7 @@ class UploadManager {
new Map<number, string>(
filesWithCollectionToUploadIn.map((mediaFile) => [
mediaFile.localID,
UploadService.getAssetName(mediaFile),
assetName(mediaFile),
]),
),
);
@ -255,7 +260,7 @@ class UploadManager {
new Map<number, string>(
analysedMediaFiles.map((mediaFile) => [
mediaFile.localID,
UploadService.getAssetName(mediaFile),
assetName(mediaFile),
]),
),
);

View file

@ -58,7 +58,6 @@ import { getFileType } from "../typeDetectionService";
import {
extractAssetMetadata,
getLivePhotoFileType,
getLivePhotoName,
getLivePhotoSize,
} from "./metadataService";
import { uploadStreamUsingMultipart } from "./multiPartUploadService";
@ -127,12 +126,6 @@ class UploadService {
: getFileSize(file);
}
getAssetName({ isLivePhoto, file, livePhotoAssets }: UploadAsset2) {
return isLivePhoto
? getLivePhotoName(livePhotoAssets)
: getFileName(file);
}
getAssetFileType({ isLivePhoto, file, livePhotoAssets }: UploadAsset) {
return isLivePhoto
? getLivePhotoFileType(livePhotoAssets)
@ -333,6 +326,19 @@ const constructPublicMagicMetadata = async (
function getFileSize(file: File | ElectronFile) {
return file.size;
}
export const getAssetName = ({
isLivePhoto,
file,
livePhotoAssets,
}: UploadAsset) =>
isLivePhoto ? getFileName(livePhotoAssets.image) : getFileName(file);
export const assetName = ({
isLivePhoto,
file,
livePhotoAssets,
}: UploadAsset2) =>
isLivePhoto ? getFileName(livePhotoAssets.image) : getFileName(file);
export const getFileName = (file: File | ElectronFile | string) =>
typeof file == "string" ? basename(file) : file.name;
@ -719,7 +725,7 @@ export async function uploader(
const { collection, localID, ...uploadAsset2 } = fileWithCollection;
/* TODO(MR): ElectronFile changes */
const uploadAsset = uploadAsset2 as UploadAsset;
const fileNameSize = `${uploadService.getAssetName(
const fileNameSize = `${assetName(
fileWithCollection,
)}_${convertBytesToHumanReadable(uploadService.getAssetSize(uploadAsset))}`;