Cache name

This commit is contained in:
Manav Rathi 2024-04-25 15:33:44 +05:30
parent 4ae4e42260
commit ac9a272c70
No known key found for this signature in database

View file

@ -501,7 +501,6 @@ class UploadManager {
} }
private async uploadMediaFiles(mediaFiles: FileWithCollection2[]) { private async uploadMediaFiles(mediaFiles: FileWithCollection2[]) {
log.info(`uploadMediaFiles called`);
this.filesToBeUploaded = [...this.filesToBeUploaded, ...mediaFiles]; this.filesToBeUploaded = [...this.filesToBeUploaded, ...mediaFiles];
if (isElectron()) { if (isElectron()) {
@ -761,11 +760,14 @@ type ClusterableFile = {
localID: number; localID: number;
collectionID: number; collectionID: number;
// fileOrPath: File | ElectronFile | string; // fileOrPath: File | ElectronFile | string;
file?: File | ElectronFile | string; file: File | string;
}; };
type ClusteredFile = ClusterableFile & { type ClusteredFile = {
localID: number;
collectionID: number;
isLivePhoto: boolean; isLivePhoto: boolean;
file?: File | string;
livePhotoAssets?: LivePhotoAssets2; livePhotoAssets?: LivePhotoAssets2;
}; };
@ -773,32 +775,35 @@ type ClusteredFile = ClusterableFile & {
* Go through the given files, combining any sibling image + video assets into a * Go through the given files, combining any sibling image + video assets into a
* single live photo when appropriate. * single live photo when appropriate.
*/ */
const clusterLivePhotos = (mediaFiles: ClusterableFile[]) => { const clusterLivePhotos = (files: ClusterableFile[]) => {
const result: ClusteredFile[] = []; const result: ClusteredFile[] = [];
mediaFiles const filesWithName: (ClusterableFile & { fileName: string })[] = files.map(
(f) => {
return { ...f, fileName: getFileName(f.file) };
},
);
filesWithName
.sort((f, g) => .sort((f, g) =>
nameAndExtension(getFileName(f.file))[0].localeCompare( nameAndExtension(f.fileName)[0].localeCompare(
nameAndExtension(getFileName(g.file))[0], nameAndExtension(g.fileName)[0],
), ),
) )
.sort((f, g) => f.collectionID - g.collectionID); .sort((f, g) => f.collectionID - g.collectionID);
let index = 0; let index = 0;
while (index < mediaFiles.length - 1) { while (index < filesWithName.length - 1) {
const f = mediaFiles[index]; const f = filesWithName[index];
const g = mediaFiles[index + 1]; const g = filesWithName[index + 1];
const fFileName = getFileName(f.file); const fFileType = potentialFileTypeFromExtension(f.fileName);
const gFileName = getFileName(g.file); const gFileType = potentialFileTypeFromExtension(g.fileName);
const fFileType = potentialFileTypeFromExtension(fFileName);
const gFileType = potentialFileTypeFromExtension(gFileName);
const fa: PotentialLivePhotoAsset = { const fa: PotentialLivePhotoAsset = {
fileName: fFileName, fileName: f.fileName,
fileType: fFileType, fileType: fFileType,
collectionID: f.collectionID, collectionID: f.collectionID,
/* TODO(MR): ElectronFile changes */ /* TODO(MR): ElectronFile changes */
size: (f as FileWithCollection).file.size, size: (f as FileWithCollection).file.size,
}; };
const ga: PotentialLivePhotoAsset = { const ga: PotentialLivePhotoAsset = {
fileName: gFileName, fileName: g.fileName,
fileType: gFileType, fileType: gFileType,
collectionID: g.collectionID, collectionID: g.collectionID,
/* TODO(MR): ElectronFile changes */ /* TODO(MR): ElectronFile changes */
@ -810,13 +815,8 @@ const clusterLivePhotos = (mediaFiles: ClusterableFile[]) => {
collectionID: f.collectionID, collectionID: f.collectionID,
isLivePhoto: true, isLivePhoto: true,
livePhotoAssets: { livePhotoAssets: {
/* TODO(MR): ElectronFile changes */ image: fFileType == FILE_TYPE.IMAGE ? f.file : g.file,
image: (fFileType == FILE_TYPE.IMAGE ? f.file : g.file) as video: fFileType == FILE_TYPE.IMAGE ? g.file : f.file,
| string
| File,
video: (fFileType == FILE_TYPE.IMAGE ? g.file : f.file) as
| string
| File,
}, },
}); });
index += 2; index += 2;
@ -828,9 +828,9 @@ const clusterLivePhotos = (mediaFiles: ClusterableFile[]) => {
index += 1; index += 1;
} }
} }
if (index === mediaFiles.length - 1) { if (index === filesWithName.length - 1) {
result.push({ result.push({
...mediaFiles[index], ...filesWithName[index],
isLivePhoto: false, isLivePhoto: false,
}); });
} }