This commit is contained in:
Manav Rathi 2024-04-13 18:09:32 +05:30
parent 1ffa905f99
commit 37cb2aaaf9
No known key found for this signature in database
2 changed files with 30 additions and 34 deletions

View file

@ -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 {

View file

@ -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();
}
};