|
@@ -1,7 +1,30 @@
|
|
|
|
+import log from "@/next/log";
|
|
|
|
+import type { Electron } from "@/next/types/ipc";
|
|
|
|
+import { CustomError } from "@ente/shared/error";
|
|
|
|
+import { Events, eventBus } from "@ente/shared/events";
|
|
import { logError } from "@ente/shared/sentry";
|
|
import { logError } from "@ente/shared/sentry";
|
|
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
|
|
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
|
|
|
|
+import { User } from "@ente/shared/user/types";
|
|
import { sleep } from "@ente/shared/utils";
|
|
import { sleep } from "@ente/shared/utils";
|
|
|
|
+import QueueProcessor, {
|
|
|
|
+ CancellationStatus,
|
|
|
|
+ RequestCanceller,
|
|
|
|
+} from "@ente/shared/utils/queueProcessor";
|
|
|
|
+import { ExportStage } from "constants/export";
|
|
|
|
+import { FILE_TYPE } from "constants/file";
|
|
|
|
+import { Collection } from "types/collection";
|
|
|
|
+import {
|
|
|
|
+ ExportProgress,
|
|
|
|
+ ExportRecord,
|
|
|
|
+ ExportSettings,
|
|
|
|
+ ExportUIUpdaters,
|
|
|
|
+} from "types/export";
|
|
import { EnteFile } from "types/file";
|
|
import { EnteFile } from "types/file";
|
|
|
|
+import {
|
|
|
|
+ constructCollectionNameMap,
|
|
|
|
+ getCollectionUserFacingName,
|
|
|
|
+ getNonEmptyPersonalCollections,
|
|
|
|
+} from "utils/collection";
|
|
import {
|
|
import {
|
|
convertCollectionIDExportNameObjectToMap,
|
|
convertCollectionIDExportNameObjectToMap,
|
|
convertFileIDExportNameObjectToMap,
|
|
convertFileIDExportNameObjectToMap,
|
|
@@ -25,41 +48,16 @@ import {
|
|
isLivePhotoExportName,
|
|
isLivePhotoExportName,
|
|
parseLivePhotoExportName,
|
|
parseLivePhotoExportName,
|
|
} from "utils/export";
|
|
} from "utils/export";
|
|
-import { getAllLocalCollections } from "../collectionService";
|
|
|
|
-import downloadManager from "../download";
|
|
|
|
-import { getAllLocalFiles } from "../fileService";
|
|
|
|
-
|
|
|
|
import {
|
|
import {
|
|
generateStreamFromArrayBuffer,
|
|
generateStreamFromArrayBuffer,
|
|
getPersonalFiles,
|
|
getPersonalFiles,
|
|
getUpdatedEXIFFileForDownload,
|
|
getUpdatedEXIFFileForDownload,
|
|
mergeMetadata,
|
|
mergeMetadata,
|
|
} from "utils/file";
|
|
} from "utils/file";
|
|
|
|
+import { getAllLocalCollections } from "../collectionService";
|
|
|
|
+import downloadManager from "../download";
|
|
|
|
+import { getAllLocalFiles } from "../fileService";
|
|
import { decodeLivePhoto } from "../livePhotoService";
|
|
import { decodeLivePhoto } from "../livePhotoService";
|
|
-
|
|
|
|
-import ElectronAPIs from "@/next/electron";
|
|
|
|
-import { CustomError } from "@ente/shared/error";
|
|
|
|
-import { Events, eventBus } from "@ente/shared/events";
|
|
|
|
-import { addLogLine } from "@ente/shared/logging";
|
|
|
|
-import { User } from "@ente/shared/user/types";
|
|
|
|
-import QueueProcessor, {
|
|
|
|
- CancellationStatus,
|
|
|
|
- RequestCanceller,
|
|
|
|
-} from "@ente/shared/utils/queueProcessor";
|
|
|
|
-import { ExportStage } from "constants/export";
|
|
|
|
-import { FILE_TYPE } from "constants/file";
|
|
|
|
-import { Collection } from "types/collection";
|
|
|
|
-import {
|
|
|
|
- ExportProgress,
|
|
|
|
- ExportRecord,
|
|
|
|
- ExportSettings,
|
|
|
|
- ExportUIUpdaters,
|
|
|
|
-} from "types/export";
|
|
|
|
-import {
|
|
|
|
- constructCollectionNameMap,
|
|
|
|
- getCollectionUserFacingName,
|
|
|
|
- getNonEmptyPersonalCollections,
|
|
|
|
-} from "utils/collection";
|
|
|
|
import { migrateExport } from "./migration";
|
|
import { migrateExport } from "./migration";
|
|
|
|
|
|
const EXPORT_RECORD_FILE_NAME = "export_status.json";
|
|
const EXPORT_RECORD_FILE_NAME = "export_status.json";
|
|
@@ -74,6 +72,8 @@ export const NULL_EXPORT_RECORD: ExportRecord = {
|
|
collectionExportNames: {},
|
|
collectionExportNames: {},
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+let electron: Electron;
|
|
|
|
+
|
|
class ExportService {
|
|
class ExportService {
|
|
private exportSettings: ExportSettings;
|
|
private exportSettings: ExportSettings;
|
|
private exportInProgress: RequestCanceller = null;
|
|
private exportInProgress: RequestCanceller = null;
|
|
@@ -93,6 +93,15 @@ class ExportService {
|
|
failed: 0,
|
|
failed: 0,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ constructor() {
|
|
|
|
+ const et = globalThis.electron;
|
|
|
|
+ if (!et)
|
|
|
|
+ throw new Error(
|
|
|
|
+ "Attempting to initialize ExportService in an unsupported non-electron context",
|
|
|
|
+ );
|
|
|
|
+ electron = et;
|
|
|
|
+ }
|
|
|
|
+
|
|
getExportSettings(): ExportSettings {
|
|
getExportSettings(): ExportSettings {
|
|
try {
|
|
try {
|
|
if (this.exportSettings) {
|
|
if (this.exportSettings) {
|
|
@@ -125,9 +134,9 @@ class ExportService {
|
|
updateProgress: (progress: ExportProgress) => void,
|
|
updateProgress: (progress: ExportProgress) => void,
|
|
) {
|
|
) {
|
|
try {
|
|
try {
|
|
- addLogLine("running migration");
|
|
|
|
|
|
+ log.info("running migration");
|
|
await migrateExport(exportDir, exportRecord, updateProgress);
|
|
await migrateExport(exportDir, exportRecord, updateProgress);
|
|
- addLogLine("migration completed");
|
|
|
|
|
|
+ log.info("migration completed");
|
|
} catch (e) {
|
|
} catch (e) {
|
|
logError(e, "migration failed");
|
|
logError(e, "migration failed");
|
|
throw e;
|
|
throw e;
|
|
@@ -160,12 +169,12 @@ class ExportService {
|
|
|
|
|
|
async changeExportDirectory() {
|
|
async changeExportDirectory() {
|
|
try {
|
|
try {
|
|
- const newRootDir = await ElectronAPIs.selectDirectory();
|
|
|
|
|
|
+ const newRootDir = await electron.selectDirectory();
|
|
if (!newRootDir) {
|
|
if (!newRootDir) {
|
|
throw Error(CustomError.SELECT_FOLDER_ABORTED);
|
|
throw Error(CustomError.SELECT_FOLDER_ABORTED);
|
|
}
|
|
}
|
|
const newExportDir = `${newRootDir}/${ENTE_EXPORT_DIRECTORY}`;
|
|
const newExportDir = `${newRootDir}/${ENTE_EXPORT_DIRECTORY}`;
|
|
- await ElectronAPIs.checkExistsAndCreateDir(newExportDir);
|
|
|
|
|
|
+ await electron.checkExistsAndCreateDir(newExportDir);
|
|
return newExportDir;
|
|
return newExportDir;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
if (e.message !== CustomError.SELECT_FOLDER_ABORTED) {
|
|
if (e.message !== CustomError.SELECT_FOLDER_ABORTED) {
|
|
@@ -178,10 +187,10 @@ class ExportService {
|
|
enableContinuousExport() {
|
|
enableContinuousExport() {
|
|
try {
|
|
try {
|
|
if (this.continuousExportEventHandler) {
|
|
if (this.continuousExportEventHandler) {
|
|
- addLogLine("continuous export already enabled");
|
|
|
|
|
|
+ log.info("continuous export already enabled");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- addLogLine("enabling continuous export");
|
|
|
|
|
|
+ log.info("enabling continuous export");
|
|
this.continuousExportEventHandler = () => {
|
|
this.continuousExportEventHandler = () => {
|
|
this.scheduleExport();
|
|
this.scheduleExport();
|
|
};
|
|
};
|
|
@@ -199,10 +208,10 @@ class ExportService {
|
|
disableContinuousExport() {
|
|
disableContinuousExport() {
|
|
try {
|
|
try {
|
|
if (!this.continuousExportEventHandler) {
|
|
if (!this.continuousExportEventHandler) {
|
|
- addLogLine("continuous export already disabled");
|
|
|
|
|
|
+ log.info("continuous export already disabled");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- addLogLine("disabling continuous export");
|
|
|
|
|
|
+ log.info("disabling continuous export");
|
|
eventBus.removeListener(
|
|
eventBus.removeListener(
|
|
Events.LOCAL_FILES_UPDATED,
|
|
Events.LOCAL_FILES_UPDATED,
|
|
this.continuousExportEventHandler,
|
|
this.continuousExportEventHandler,
|
|
@@ -277,7 +286,7 @@ class ExportService {
|
|
|
|
|
|
async stopRunningExport() {
|
|
async stopRunningExport() {
|
|
try {
|
|
try {
|
|
- addLogLine("user requested export cancellation");
|
|
|
|
|
|
+ log.info("user requested export cancellation");
|
|
this.exportInProgress.exec();
|
|
this.exportInProgress.exec();
|
|
this.exportInProgress = null;
|
|
this.exportInProgress = null;
|
|
this.reRunNeeded = false;
|
|
this.reRunNeeded = false;
|
|
@@ -290,11 +299,11 @@ class ExportService {
|
|
scheduleExport = async () => {
|
|
scheduleExport = async () => {
|
|
try {
|
|
try {
|
|
if (this.exportInProgress) {
|
|
if (this.exportInProgress) {
|
|
- addLogLine("export in progress, scheduling re-run");
|
|
|
|
|
|
+ log.info("export in progress, scheduling re-run");
|
|
this.reRunNeeded = true;
|
|
this.reRunNeeded = true;
|
|
return;
|
|
return;
|
|
} else {
|
|
} else {
|
|
- addLogLine("export not in progress, starting export");
|
|
|
|
|
|
+ log.info("export not in progress, starting export");
|
|
}
|
|
}
|
|
|
|
|
|
const isCanceled: CancellationStatus = { status: false };
|
|
const isCanceled: CancellationStatus = { status: false };
|
|
@@ -307,22 +316,22 @@ class ExportService {
|
|
try {
|
|
try {
|
|
const exportFolder = this.getExportSettings()?.folder;
|
|
const exportFolder = this.getExportSettings()?.folder;
|
|
await this.preExport(exportFolder);
|
|
await this.preExport(exportFolder);
|
|
- addLogLine("export started");
|
|
|
|
|
|
+ log.info("export started");
|
|
await this.runExport(exportFolder, isCanceled);
|
|
await this.runExport(exportFolder, isCanceled);
|
|
- addLogLine("export completed");
|
|
|
|
|
|
+ log.info("export completed");
|
|
} finally {
|
|
} finally {
|
|
if (isCanceled.status) {
|
|
if (isCanceled.status) {
|
|
- addLogLine("export cancellation done");
|
|
|
|
|
|
+ log.info("export cancellation done");
|
|
if (!this.exportInProgress) {
|
|
if (!this.exportInProgress) {
|
|
await this.postExport();
|
|
await this.postExport();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
await this.postExport();
|
|
await this.postExport();
|
|
- addLogLine("resetting export in progress after completion");
|
|
|
|
|
|
+ log.info("resetting export in progress after completion");
|
|
this.exportInProgress = null;
|
|
this.exportInProgress = null;
|
|
if (this.reRunNeeded) {
|
|
if (this.reRunNeeded) {
|
|
this.reRunNeeded = false;
|
|
this.reRunNeeded = false;
|
|
- addLogLine("re-running export");
|
|
|
|
|
|
+ log.info("re-running export");
|
|
setTimeout(() => this.scheduleExport(), 0);
|
|
setTimeout(() => this.scheduleExport(), 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -390,7 +399,7 @@ class ExportService {
|
|
exportRecord,
|
|
exportRecord,
|
|
);
|
|
);
|
|
|
|
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`personal files:${personalFiles.length} unexported files: ${filesToExport.length}, deleted exported files: ${removedFileUIDs.length}, renamed collections: ${renamedCollections.length}, deleted collections: ${deletedExportedCollections.length}`,
|
|
`personal files:${personalFiles.length} unexported files: ${filesToExport.length}, deleted exported files: ${removedFileUIDs.length}, renamed collections: ${renamedCollections.length}, deleted collections: ${deletedExportedCollections.length}`,
|
|
);
|
|
);
|
|
let success = 0;
|
|
let success = 0;
|
|
@@ -416,7 +425,7 @@ class ExportService {
|
|
};
|
|
};
|
|
if (renamedCollections?.length > 0) {
|
|
if (renamedCollections?.length > 0) {
|
|
this.updateExportStage(ExportStage.RENAMING_COLLECTION_FOLDERS);
|
|
this.updateExportStage(ExportStage.RENAMING_COLLECTION_FOLDERS);
|
|
- addLogLine(`renaming ${renamedCollections.length} collections`);
|
|
|
|
|
|
+ log.info(`renaming ${renamedCollections.length} collections`);
|
|
await this.collectionRenamer(
|
|
await this.collectionRenamer(
|
|
exportFolder,
|
|
exportFolder,
|
|
collectionIDExportNameMap,
|
|
collectionIDExportNameMap,
|
|
@@ -427,7 +436,7 @@ class ExportService {
|
|
|
|
|
|
if (removedFileUIDs?.length > 0) {
|
|
if (removedFileUIDs?.length > 0) {
|
|
this.updateExportStage(ExportStage.TRASHING_DELETED_FILES);
|
|
this.updateExportStage(ExportStage.TRASHING_DELETED_FILES);
|
|
- addLogLine(`trashing ${removedFileUIDs.length} files`);
|
|
|
|
|
|
+ log.info(`trashing ${removedFileUIDs.length} files`);
|
|
await this.fileTrasher(
|
|
await this.fileTrasher(
|
|
exportFolder,
|
|
exportFolder,
|
|
collectionIDExportNameMap,
|
|
collectionIDExportNameMap,
|
|
@@ -437,7 +446,7 @@ class ExportService {
|
|
}
|
|
}
|
|
if (filesToExport?.length > 0) {
|
|
if (filesToExport?.length > 0) {
|
|
this.updateExportStage(ExportStage.EXPORTING_FILES);
|
|
this.updateExportStage(ExportStage.EXPORTING_FILES);
|
|
- addLogLine(`exporting ${filesToExport.length} files`);
|
|
|
|
|
|
+ log.info(`exporting ${filesToExport.length} files`);
|
|
await this.fileExporter(
|
|
await this.fileExporter(
|
|
filesToExport,
|
|
filesToExport,
|
|
collectionIDNameMap,
|
|
collectionIDNameMap,
|
|
@@ -452,7 +461,7 @@ class ExportService {
|
|
this.updateExportStage(
|
|
this.updateExportStage(
|
|
ExportStage.TRASHING_DELETED_COLLECTIONS,
|
|
ExportStage.TRASHING_DELETED_COLLECTIONS,
|
|
);
|
|
);
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`removing ${deletedExportedCollections.length} collections`,
|
|
`removing ${deletedExportedCollections.length} collections`,
|
|
);
|
|
);
|
|
await this.collectionRemover(
|
|
await this.collectionRemover(
|
|
@@ -497,7 +506,7 @@ class ExportService {
|
|
exportFolder,
|
|
exportFolder,
|
|
getCollectionUserFacingName(collection),
|
|
getCollectionUserFacingName(collection),
|
|
);
|
|
);
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`renaming collection with id ${collection.id} from ${oldCollectionExportName} to ${newCollectionExportName}`,
|
|
`renaming collection with id ${collection.id} from ${oldCollectionExportName} to ${newCollectionExportName}`,
|
|
);
|
|
);
|
|
const newCollectionExportPath = getCollectionExportPath(
|
|
const newCollectionExportPath = getCollectionExportPath(
|
|
@@ -515,7 +524,7 @@ class ExportService {
|
|
newCollectionExportName,
|
|
newCollectionExportName,
|
|
);
|
|
);
|
|
try {
|
|
try {
|
|
- await ElectronAPIs.rename(
|
|
|
|
|
|
+ await electron.rename(
|
|
oldCollectionExportPath,
|
|
oldCollectionExportPath,
|
|
newCollectionExportPath,
|
|
newCollectionExportPath,
|
|
);
|
|
);
|
|
@@ -531,7 +540,7 @@ class ExportService {
|
|
);
|
|
);
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`renaming collection with id ${collection.id} from ${oldCollectionExportName} to ${newCollectionExportName} successful`,
|
|
`renaming collection with id ${collection.id} from ${oldCollectionExportName} to ${newCollectionExportName} successful`,
|
|
);
|
|
);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -575,7 +584,7 @@ class ExportService {
|
|
throw Error(CustomError.EXPORT_STOPPED);
|
|
throw Error(CustomError.EXPORT_STOPPED);
|
|
}
|
|
}
|
|
await this.verifyExportFolderExists(exportFolder);
|
|
await this.verifyExportFolderExists(exportFolder);
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`removing collection with id ${collectionID} from export folder`,
|
|
`removing collection with id ${collectionID} from export folder`,
|
|
);
|
|
);
|
|
const collectionExportName =
|
|
const collectionExportName =
|
|
@@ -600,11 +609,11 @@ class ExportService {
|
|
);
|
|
);
|
|
try {
|
|
try {
|
|
// delete the collection metadata folder
|
|
// delete the collection metadata folder
|
|
- await ElectronAPIs.deleteFolder(
|
|
|
|
|
|
+ await electron.deleteFolder(
|
|
getMetadataFolderExportPath(collectionExportPath),
|
|
getMetadataFolderExportPath(collectionExportPath),
|
|
);
|
|
);
|
|
// delete the collection folder
|
|
// delete the collection folder
|
|
- await ElectronAPIs.deleteFolder(collectionExportPath);
|
|
|
|
|
|
+ await electron.deleteFolder(collectionExportPath);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
await this.addCollectionExportedRecord(
|
|
await this.addCollectionExportedRecord(
|
|
exportFolder,
|
|
exportFolder,
|
|
@@ -613,7 +622,7 @@ class ExportService {
|
|
);
|
|
);
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`removing collection with id ${collectionID} from export folder successful`,
|
|
`removing collection with id ${collectionID} from export folder successful`,
|
|
);
|
|
);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -651,7 +660,7 @@ class ExportService {
|
|
): Promise<void> {
|
|
): Promise<void> {
|
|
try {
|
|
try {
|
|
for (const file of files) {
|
|
for (const file of files) {
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`exporting file ${file.metadata.title} with id ${
|
|
`exporting file ${file.metadata.title} with id ${
|
|
file.id
|
|
file.id
|
|
} from collection ${collectionIDNameMap.get(
|
|
} from collection ${collectionIDNameMap.get(
|
|
@@ -687,10 +696,10 @@ class ExportService {
|
|
exportDir,
|
|
exportDir,
|
|
collectionExportName,
|
|
collectionExportName,
|
|
);
|
|
);
|
|
- await ElectronAPIs.checkExistsAndCreateDir(
|
|
|
|
|
|
+ await electron.checkExistsAndCreateDir(
|
|
collectionExportPath,
|
|
collectionExportPath,
|
|
);
|
|
);
|
|
- await ElectronAPIs.checkExistsAndCreateDir(
|
|
|
|
|
|
+ await electron.checkExistsAndCreateDir(
|
|
getMetadataFolderExportPath(collectionExportPath),
|
|
getMetadataFolderExportPath(collectionExportPath),
|
|
);
|
|
);
|
|
await this.downloadAndSave(
|
|
await this.downloadAndSave(
|
|
@@ -699,7 +708,7 @@ class ExportService {
|
|
file,
|
|
file,
|
|
);
|
|
);
|
|
incrementSuccess();
|
|
incrementSuccess();
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`exporting file ${file.metadata.title} with id ${
|
|
`exporting file ${file.metadata.title} with id ${
|
|
file.id
|
|
file.id
|
|
} from collection ${collectionIDNameMap.get(
|
|
} from collection ${collectionIDNameMap.get(
|
|
@@ -744,7 +753,7 @@ class ExportService {
|
|
);
|
|
);
|
|
for (const fileUID of removedFileUIDs) {
|
|
for (const fileUID of removedFileUIDs) {
|
|
await this.verifyExportFolderExists(exportDir);
|
|
await this.verifyExportFolderExists(exportDir);
|
|
- addLogLine(`trashing file with id ${fileUID}`);
|
|
|
|
|
|
+ log.info(`trashing file with id ${fileUID}`);
|
|
if (isCanceled.status) {
|
|
if (isCanceled.status) {
|
|
throw Error(CustomError.EXPORT_STOPPED);
|
|
throw Error(CustomError.EXPORT_STOPPED);
|
|
}
|
|
}
|
|
@@ -766,11 +775,11 @@ class ExportService {
|
|
collectionExportPath,
|
|
collectionExportPath,
|
|
imageExportName,
|
|
imageExportName,
|
|
);
|
|
);
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`moving image file ${imageExportPath} to trash folder`,
|
|
`moving image file ${imageExportPath} to trash folder`,
|
|
);
|
|
);
|
|
if (await this.exists(imageExportPath)) {
|
|
if (await this.exists(imageExportPath)) {
|
|
- await ElectronAPIs.moveFile(
|
|
|
|
|
|
+ await electron.moveFile(
|
|
imageExportPath,
|
|
imageExportPath,
|
|
await getTrashedFileExportPath(
|
|
await getTrashedFileExportPath(
|
|
exportDir,
|
|
exportDir,
|
|
@@ -785,7 +794,7 @@ class ExportService {
|
|
if (
|
|
if (
|
|
await this.exists(imageMetadataFileExportPath)
|
|
await this.exists(imageMetadataFileExportPath)
|
|
) {
|
|
) {
|
|
- await ElectronAPIs.moveFile(
|
|
|
|
|
|
+ await electron.moveFile(
|
|
imageMetadataFileExportPath,
|
|
imageMetadataFileExportPath,
|
|
await getTrashedFileExportPath(
|
|
await getTrashedFileExportPath(
|
|
exportDir,
|
|
exportDir,
|
|
@@ -798,11 +807,11 @@ class ExportService {
|
|
collectionExportPath,
|
|
collectionExportPath,
|
|
videoExportName,
|
|
videoExportName,
|
|
);
|
|
);
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`moving video file ${videoExportPath} to trash folder`,
|
|
`moving video file ${videoExportPath} to trash folder`,
|
|
);
|
|
);
|
|
if (await this.exists(videoExportPath)) {
|
|
if (await this.exists(videoExportPath)) {
|
|
- await ElectronAPIs.moveFile(
|
|
|
|
|
|
+ await electron.moveFile(
|
|
videoExportPath,
|
|
videoExportPath,
|
|
await getTrashedFileExportPath(
|
|
await getTrashedFileExportPath(
|
|
exportDir,
|
|
exportDir,
|
|
@@ -815,7 +824,7 @@ class ExportService {
|
|
if (
|
|
if (
|
|
await this.exists(videoMetadataFileExportPath)
|
|
await this.exists(videoMetadataFileExportPath)
|
|
) {
|
|
) {
|
|
- await ElectronAPIs.moveFile(
|
|
|
|
|
|
+ await electron.moveFile(
|
|
videoMetadataFileExportPath,
|
|
videoMetadataFileExportPath,
|
|
await getTrashedFileExportPath(
|
|
await getTrashedFileExportPath(
|
|
exportDir,
|
|
exportDir,
|
|
@@ -833,11 +842,11 @@ class ExportService {
|
|
exportDir,
|
|
exportDir,
|
|
fileExportPath,
|
|
fileExportPath,
|
|
);
|
|
);
|
|
- addLogLine(
|
|
|
|
|
|
+ log.info(
|
|
`moving file ${fileExportPath} to ${trashedFilePath} trash folder`,
|
|
`moving file ${fileExportPath} to ${trashedFilePath} trash folder`,
|
|
);
|
|
);
|
|
if (await this.exists(fileExportPath)) {
|
|
if (await this.exists(fileExportPath)) {
|
|
- await ElectronAPIs.moveFile(
|
|
|
|
|
|
+ await electron.moveFile(
|
|
fileExportPath,
|
|
fileExportPath,
|
|
trashedFilePath,
|
|
trashedFilePath,
|
|
);
|
|
);
|
|
@@ -845,7 +854,7 @@ class ExportService {
|
|
const metadataFileExportPath =
|
|
const metadataFileExportPath =
|
|
getMetadataFileExportPath(fileExportPath);
|
|
getMetadataFileExportPath(fileExportPath);
|
|
if (await this.exists(metadataFileExportPath)) {
|
|
if (await this.exists(metadataFileExportPath)) {
|
|
- await ElectronAPIs.moveFile(
|
|
|
|
|
|
+ await electron.moveFile(
|
|
metadataFileExportPath,
|
|
metadataFileExportPath,
|
|
await getTrashedFileExportPath(
|
|
await getTrashedFileExportPath(
|
|
exportDir,
|
|
exportDir,
|
|
@@ -862,7 +871,7 @@ class ExportService {
|
|
);
|
|
);
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
- addLogLine(`trashing file with id ${fileUID} successful`);
|
|
|
|
|
|
+ log.info(`trashing file with id ${fileUID} successful`);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
logError(e, "trashing failed for a file");
|
|
logError(e, "trashing failed for a file");
|
|
if (
|
|
if (
|
|
@@ -984,7 +993,7 @@ class ExportService {
|
|
try {
|
|
try {
|
|
const exportRecord = await this.getExportRecord(folder);
|
|
const exportRecord = await this.getExportRecord(folder);
|
|
const newRecord: ExportRecord = { ...exportRecord, ...newData };
|
|
const newRecord: ExportRecord = { ...exportRecord, ...newData };
|
|
- await ElectronAPIs.saveFileToDisk(
|
|
|
|
|
|
+ await electron.saveFileToDisk(
|
|
`${folder}/${EXPORT_RECORD_FILE_NAME}`,
|
|
`${folder}/${EXPORT_RECORD_FILE_NAME}`,
|
|
JSON.stringify(newRecord, null, 2),
|
|
JSON.stringify(newRecord, null, 2),
|
|
);
|
|
);
|
|
@@ -1006,7 +1015,7 @@ class ExportService {
|
|
return this.createEmptyExportRecord(exportRecordJSONPath);
|
|
return this.createEmptyExportRecord(exportRecordJSONPath);
|
|
}
|
|
}
|
|
const recordFile =
|
|
const recordFile =
|
|
- await ElectronAPIs.readTextFile(exportRecordJSONPath);
|
|
|
|
|
|
+ await electron.readTextFile(exportRecordJSONPath);
|
|
try {
|
|
try {
|
|
return JSON.parse(recordFile);
|
|
return JSON.parse(recordFile);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -1042,8 +1051,8 @@ class ExportService {
|
|
exportFolder,
|
|
exportFolder,
|
|
collectionExportName,
|
|
collectionExportName,
|
|
);
|
|
);
|
|
- await ElectronAPIs.checkExistsAndCreateDir(collectionExportPath);
|
|
|
|
- await ElectronAPIs.checkExistsAndCreateDir(
|
|
|
|
|
|
+ await electron.checkExistsAndCreateDir(collectionExportPath);
|
|
|
|
+ await electron.checkExistsAndCreateDir(
|
|
getMetadataFolderExportPath(collectionExportPath),
|
|
getMetadataFolderExportPath(collectionExportPath),
|
|
);
|
|
);
|
|
|
|
|
|
@@ -1090,7 +1099,7 @@ class ExportService {
|
|
fileExportName,
|
|
fileExportName,
|
|
file,
|
|
file,
|
|
);
|
|
);
|
|
- await ElectronAPIs.saveStreamToDisk(
|
|
|
|
|
|
+ await electron.saveStreamToDisk(
|
|
getFileExportPath(collectionExportPath, fileExportName),
|
|
getFileExportPath(collectionExportPath, fileExportName),
|
|
updatedFileStream,
|
|
updatedFileStream,
|
|
);
|
|
);
|
|
@@ -1138,7 +1147,7 @@ class ExportService {
|
|
imageExportName,
|
|
imageExportName,
|
|
file,
|
|
file,
|
|
);
|
|
);
|
|
- await ElectronAPIs.saveStreamToDisk(
|
|
|
|
|
|
+ await electron.saveStreamToDisk(
|
|
getFileExportPath(collectionExportPath, imageExportName),
|
|
getFileExportPath(collectionExportPath, imageExportName),
|
|
imageStream,
|
|
imageStream,
|
|
);
|
|
);
|
|
@@ -1150,12 +1159,12 @@ class ExportService {
|
|
file,
|
|
file,
|
|
);
|
|
);
|
|
try {
|
|
try {
|
|
- await ElectronAPIs.saveStreamToDisk(
|
|
|
|
|
|
+ await electron.saveStreamToDisk(
|
|
getFileExportPath(collectionExportPath, videoExportName),
|
|
getFileExportPath(collectionExportPath, videoExportName),
|
|
videoStream,
|
|
videoStream,
|
|
);
|
|
);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
- await ElectronAPIs.deleteFile(
|
|
|
|
|
|
+ await electron.deleteFile(
|
|
getFileExportPath(collectionExportPath, imageExportName),
|
|
getFileExportPath(collectionExportPath, imageExportName),
|
|
);
|
|
);
|
|
throw e;
|
|
throw e;
|
|
@@ -1171,7 +1180,7 @@ class ExportService {
|
|
fileExportName: string,
|
|
fileExportName: string,
|
|
file: EnteFile,
|
|
file: EnteFile,
|
|
) {
|
|
) {
|
|
- await ElectronAPIs.saveFileToDisk(
|
|
|
|
|
|
+ await electron.saveFileToDisk(
|
|
getFileMetadataExportPath(collectionExportPath, fileExportName),
|
|
getFileMetadataExportPath(collectionExportPath, fileExportName),
|
|
getGoogleLikeMetadataFile(fileExportName, file),
|
|
getGoogleLikeMetadataFile(fileExportName, file),
|
|
);
|
|
);
|
|
@@ -1182,15 +1191,15 @@ class ExportService {
|
|
};
|
|
};
|
|
|
|
|
|
exists = (path: string) => {
|
|
exists = (path: string) => {
|
|
- return ElectronAPIs.fs.exists(path);
|
|
|
|
|
|
+ return electron.fs.exists(path);
|
|
};
|
|
};
|
|
|
|
|
|
rename = (oldPath: string, newPath: string) => {
|
|
rename = (oldPath: string, newPath: string) => {
|
|
- return ElectronAPIs.rename(oldPath, newPath);
|
|
|
|
|
|
+ return electron.rename(oldPath, newPath);
|
|
};
|
|
};
|
|
|
|
|
|
checkExistsAndCreateDir = (path: string) => {
|
|
checkExistsAndCreateDir = (path: string) => {
|
|
- return ElectronAPIs.checkExistsAndCreateDir(path);
|
|
|
|
|
|
+ return electron.checkExistsAndCreateDir(path);
|
|
};
|
|
};
|
|
|
|
|
|
exportFolderExists = async (exportFolder: string) => {
|
|
exportFolderExists = async (exportFolder: string) => {
|
|
@@ -1212,7 +1221,7 @@ class ExportService {
|
|
|
|
|
|
private createEmptyExportRecord = async (exportRecordJSONPath: string) => {
|
|
private createEmptyExportRecord = async (exportRecordJSONPath: string) => {
|
|
const exportRecord: ExportRecord = NULL_EXPORT_RECORD;
|
|
const exportRecord: ExportRecord = NULL_EXPORT_RECORD;
|
|
- await ElectronAPIs.saveFileToDisk(
|
|
|
|
|
|
+ await electron.saveFileToDisk(
|
|
exportRecordJSONPath,
|
|
exportRecordJSONPath,
|
|
JSON.stringify(exportRecord, null, 2),
|
|
JSON.stringify(exportRecord, null, 2),
|
|
);
|
|
);
|