Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor

Manav Rathi37cb2aaaf95d
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 06961d6c9b..c31256f138 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -52,7 +52,7 @@ import "photoswipe/dist/photoswipe.css";
import { createContext, useEffect, useRef, useState } from "react";
import LoadingBar from "react-top-loading-bar";
import DownloadManager from "services/download";
-import exportService from "services/export";
+import exportService, { resumeExportsIfNeeded } from "services/export";
import mlWorkManager from "services/machineLearning/mlWorkManager";
import {
getFamilyPortalRedirectURL,
@@ -64,7 +64,6 @@ import {
NotificationAttributes,
SetNotificationAttributes,
} from "types/Notification";
-import { isExportInProgress } from "utils/export";
import {
getMLSearchConfig,
updateMLSearchConfig,
@@ -214,37 +213,10 @@ export default function App({ Component, pageProps }: AppProps) {
return;
}
const initExport = async () => {
- try {
- log.info("init export");
- const token = getToken();
- if (!token) {
- log.info(
- "User not logged in, not starting export continuous sync job",
- );
- return;
- }
- await DownloadManager.init(APPS.PHOTOS, { token });
- const exportSettings = exportService.getExportSettings();
- if (
- !(await exportService.exportFolderExists(
- exportSettings?.folder,
- ))
- ) {
- return;
- }
- const exportRecord = await exportService.getExportRecord(
- exportSettings.folder,
- );
- if (exportSettings.continuousExport) {
- exportService.enableContinuousExport();
- }
- if (isExportInProgress(exportRecord.stage)) {
- log.info("export was in progress, resuming");
- exportService.scheduleExport();
- }
- } catch (e) {
- log.error("init export failed", e);
- }
+ const token = getToken();
+ if (!token) return;
+ await DownloadManager.init(APPS.PHOTOS, { token });
+ await resumeExportsIfNeeded();
};
initExport();
try {
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 9f61e05db3..05769e6c5e 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -42,6 +42,7 @@ import {
getUnExportedFiles,
getUniqueCollectionExportName,
getUniqueFileExportName,
+ isExportInProgress,
isLivePhotoExportName,
parseLivePhotoExportName,
} from "utils/export";
@@ -1191,4 +1192,27 @@ class ExportService {
};
}
-export default new ExportService();
+const exportService = new ExportService();
+
+export default exportService;
+
+/**
+ * If there are any in-progress exports, or if continuous exports are enabled,
+ * resume them.
+ */
+export const resumeExportsIfNeeded = async () => {
+ const exportSettings = exportService.getExportSettings();
+ if (!(await exportService.exportFolderExists(exportSettings?.folder))) {
+ return;
+ }
+ const exportRecord = await exportService.getExportRecord(
+ exportSettings.folder,
+ );
+ if (exportSettings.continuousExport) {
+ exportService.enableContinuousExport();
+ }
+ if (isExportInProgress(exportRecord.stage)) {
+ log.debug(() => "Resuming in-progress export");
+ exportService.scheduleExport();
+ }
+};