add live photo removal logic

This commit is contained in:
Abhinav 2023-04-25 18:22:08 +05:30
parent 915366f82c
commit c111c00df1
2 changed files with 55 additions and 20 deletions

View file

@ -479,6 +479,46 @@ class ExportService {
} }
try { try {
const filePath = fileIDPathMap.get(fileUID); const filePath = fileIDPathMap.get(fileUID);
// check if filepath is for live photo
// livePhoto has the path in format: `JSON.stringify({image,video})`
const isLivePhotoPath =
filePath.startsWith('{') && filePath.endsWith('}');
if (isLivePhotoPath) {
const { image: imagePath, video: videoPath } =
JSON.parse(filePath);
await this.electronAPIs.moveFile(
imagePath,
getTrashedFilePath(exportDir, imagePath)
);
addLocalLog(
() =>
`moving image file ${imagePath} to trash folder`
);
const imageMetadataFilePath =
getMetadataFilePath(imagePath);
await this.electronAPIs.moveFile(
imageMetadataFilePath,
getTrashedFilePath(exportDir, imageMetadataFilePath)
);
addLocalLog(
() =>
`moving video file ${videoPath} to trash folder`
);
await this.electronAPIs.moveFile(
videoPath,
getTrashedFilePath(exportDir, videoPath)
);
const videoMetadataFilePath =
getMetadataFilePath(videoPath);
await this.electronAPIs.moveFile(
videoMetadataFilePath,
getTrashedFilePath(exportDir, videoMetadataFilePath)
);
await this.removeFileExportedRecord(exportDir, fileUID);
} else {
await this.electronAPIs.moveFile( await this.electronAPIs.moveFile(
filePath, filePath,
getTrashedFilePath(exportDir, filePath) getTrashedFilePath(exportDir, filePath)
@ -489,6 +529,7 @@ class ExportService {
getTrashedFilePath(exportDir, metadataFilePath) getTrashedFilePath(exportDir, metadataFilePath)
); );
await this.removeFileExportedRecord(exportDir, fileUID); await this.removeFileExportedRecord(exportDir, fileUID);
}
success++; success++;
} catch (e) { } catch (e) {
failed++; failed++;
@ -772,7 +813,10 @@ class ExportService {
const imageSavePath = getFileSavePath(collectionPath, imageSaveName); const imageSavePath = getFileSavePath(collectionPath, imageSaveName);
const videoSavePath = getFileSavePath(collectionPath, videoSaveName); const videoSavePath = getFileSavePath(collectionPath, videoSaveName);
return [imageSavePath, videoSavePath].join('-'); return JSON.stringify({
image: imageSavePath,
video: videoSavePath,
});
} }
private async saveMediaFile( private async saveMediaFile(

View file

@ -13,7 +13,6 @@ import { splitFilenameAndExtension } from 'utils/file';
import { ENTE_METADATA_FOLDER, ENTE_TRASH_FOLDER } from 'constants/export'; import { ENTE_METADATA_FOLDER, ENTE_TRASH_FOLDER } from 'constants/export';
import sanitize from 'sanitize-filename'; import sanitize from 'sanitize-filename';
import { formatDateTimeShort } from 'utils/time/format'; import { formatDateTimeShort } from 'utils/time/format';
import { addLocalLog } from 'utils/logging';
export const getExportRecordFileUID = (file: EnteFile) => export const getExportRecordFileUID = (file: EnteFile) =>
`${file.id}_${file.collectionID}_${file.updationTime}`; `${file.id}_${file.collectionID}_${file.updationTime}`;
@ -89,14 +88,6 @@ export const getDeletedExportedCollections = (
const presentCollections = new Set( const presentCollections = new Set(
collections.map((collection) => collection.id) collections.map((collection) => collection.id)
); );
addLocalLog(
() => `
presentCollections: ${collections.map((c) => c.id)}
exportRecord?.exportedCollectionPaths: ${JSON.stringify(
exportRecord?.exportedCollectionPaths
)}
`
);
if (!exportRecord?.exportedCollectionPaths) { if (!exportRecord?.exportedCollectionPaths) {
return []; return [];
} }