Fix export window unresponsive (#1122)
This commit is contained in:
commit
8061ce4c62
|
@ -490,6 +490,7 @@
|
|||
"PUBLIC_COLLECT_SUBTEXT": "Allow people with the link to also add photos to the shared album.",
|
||||
"STOP_EXPORT": "Stop",
|
||||
"EXPORT_PROGRESS": "<a>{{progress.success}} / {{progress.total}}</a> items synced",
|
||||
"MIGRATING_EXPORT": "Preparing...",
|
||||
"EXPORT_NOTIFICATION": {
|
||||
"START": "Export started",
|
||||
"IN_PROGRESS": "Export already in progress",
|
||||
|
|
|
@ -35,6 +35,8 @@ export default function ExportInProgress(props: Props) {
|
|||
<Box mb={1.5}>
|
||||
{isLoading ? (
|
||||
t('EXPORT_STARTING')
|
||||
) : props.exportStage === ExportStage.MIGRATION ? (
|
||||
t('MIGRATING_EXPORT')
|
||||
) : (
|
||||
<Trans
|
||||
i18nKey={'EXPORT_PROGRESS'}
|
||||
|
|
|
@ -29,7 +29,6 @@ import { getExportDirectoryDoesNotExistMessage } from 'utils/ui';
|
|||
import { t } from 'i18next';
|
||||
import LinkButton from './pages/gallery/LinkButton';
|
||||
import { CustomError } from 'utils/error';
|
||||
import { formatNumber } from 'utils/number/format';
|
||||
import { addLogLine } from 'utils/logging';
|
||||
|
||||
const ExportFolderPathContainer = styled(LinkButton)`
|
||||
|
@ -212,14 +211,6 @@ export default function ExportModal(props: Props) {
|
|||
continuousExport={continuousExport}
|
||||
toggleContinuousExport={toggleContinuousExport}
|
||||
/>
|
||||
<SpaceBetweenFlex minHeight={'48px'} pr={'16px'}>
|
||||
<Typography color="text.muted">
|
||||
{t('TOTAL_ITEMS')}
|
||||
</Typography>
|
||||
<Typography>
|
||||
{formatNumber(fileExportStats.totalCount)}
|
||||
</Typography>
|
||||
</SpaceBetweenFlex>
|
||||
</DialogContent>
|
||||
<Divider />
|
||||
<ExportDynamicContent
|
||||
|
@ -331,6 +322,7 @@ const ExportDynamicContent = ({
|
|||
return <ExportInit startExport={startExport} />;
|
||||
|
||||
case ExportStage.INPROGRESS:
|
||||
case ExportStage.MIGRATION:
|
||||
return (
|
||||
<ExportInProgress
|
||||
exportStage={exportStage}
|
||||
|
|
|
@ -5,5 +5,6 @@ export const ENTE_TRASH_FOLDER = 'Trash';
|
|||
export enum ExportStage {
|
||||
INIT = 0,
|
||||
INPROGRESS = 1,
|
||||
MIGRATION = 2,
|
||||
FINISHED = 3,
|
||||
}
|
||||
|
|
|
@ -128,10 +128,14 @@ class ExportService {
|
|||
}
|
||||
}
|
||||
|
||||
async runMigration(exportDir: string, exportRecord: ExportRecord) {
|
||||
async runMigration(
|
||||
exportDir: string,
|
||||
exportRecord: ExportRecord,
|
||||
updateProgress: (progress: ExportProgress) => void
|
||||
) {
|
||||
try {
|
||||
addLogLine('running migration');
|
||||
await migrateExport(exportDir, exportRecord);
|
||||
await migrateExport(exportDir, exportRecord, updateProgress);
|
||||
addLogLine('migration completed');
|
||||
} catch (e) {
|
||||
logError(e, 'migration failed');
|
||||
|
@ -281,14 +285,24 @@ class ExportService {
|
|||
|
||||
async preExport(exportFolder: string) {
|
||||
this.verifyExportFolderExists(exportFolder);
|
||||
const exportRecord = await this.getExportRecord(exportFolder);
|
||||
await this.updateExportStage(ExportStage.MIGRATION);
|
||||
this.updateExportProgress({
|
||||
success: 0,
|
||||
failed: 0,
|
||||
total: 0,
|
||||
});
|
||||
await this.runMigration(
|
||||
exportFolder,
|
||||
exportRecord,
|
||||
this.updateExportProgress.bind(this)
|
||||
);
|
||||
await this.updateExportStage(ExportStage.INPROGRESS);
|
||||
this.updateExportProgress({
|
||||
success: 0,
|
||||
failed: 0,
|
||||
total: 0,
|
||||
});
|
||||
const exportRecord = await this.getExportRecord(exportFolder);
|
||||
await this.runMigration(exportFolder, exportRecord);
|
||||
}
|
||||
|
||||
async postExport() {
|
||||
|
@ -312,6 +326,7 @@ class ExportService {
|
|||
|
||||
async stopRunningExport() {
|
||||
try {
|
||||
addLogLine('user requested export cancellation');
|
||||
this.exportInProgress.exec();
|
||||
this.exportInProgress = null;
|
||||
this.reRunNeeded = false;
|
||||
|
@ -344,16 +359,15 @@ class ExportService {
|
|||
addLogLine('export started');
|
||||
await this.runExport(exportFolder, isCanceled);
|
||||
addLogLine('export completed');
|
||||
await this.postExport();
|
||||
this.exportInProgress = null;
|
||||
if (this.reRunNeeded) {
|
||||
this.reRunNeeded = false;
|
||||
addLogLine('re-running export');
|
||||
setTimeout(() => this.scheduleExport(), 0);
|
||||
}
|
||||
} finally {
|
||||
if (!isCanceled.status || !this.exportInProgress) {
|
||||
if (isCanceled.status) {
|
||||
addLogLine('export cancellation done');
|
||||
if (!this.exportInProgress) {
|
||||
await this.postExport();
|
||||
}
|
||||
} else {
|
||||
await this.postExport();
|
||||
addLogLine('resetting export in progress after completion');
|
||||
this.exportInProgress = null;
|
||||
if (this.reRunNeeded) {
|
||||
this.reRunNeeded = false;
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
FileExportNames,
|
||||
ExportRecordV0,
|
||||
CollectionExportNames,
|
||||
ExportProgress,
|
||||
} from 'types/export';
|
||||
import { EnteFile } from 'types/file';
|
||||
import { User } from 'types/user';
|
||||
|
@ -38,10 +39,12 @@ import { FILE_TYPE } from 'constants/file';
|
|||
import { decodeLivePhoto } from 'services/livePhotoService';
|
||||
import downloadManager from 'services/downloadManager';
|
||||
import { retryAsyncFunction } from 'utils/network';
|
||||
import { sleep } from 'utils/common';
|
||||
|
||||
export async function migrateExport(
|
||||
exportDir: string,
|
||||
exportRecord: ExportRecordV1 | ExportRecordV2 | ExportRecord
|
||||
exportRecord: ExportRecordV1 | ExportRecordV2 | ExportRecord,
|
||||
updateProgress: (progress: ExportProgress) => void
|
||||
) {
|
||||
try {
|
||||
addLogLine(`current export version: ${exportRecord.version}`);
|
||||
|
@ -63,7 +66,11 @@ export async function migrateExport(
|
|||
}
|
||||
if (exportRecord.version === 2) {
|
||||
addLogLine('migrating export to version 3');
|
||||
await migrationV2ToV3(exportDir, exportRecord as ExportRecordV2);
|
||||
await migrationV2ToV3(
|
||||
exportDir,
|
||||
exportRecord as ExportRecordV2,
|
||||
updateProgress
|
||||
);
|
||||
exportRecord = await exportService.updateExportRecord(exportDir, {
|
||||
version: 3,
|
||||
});
|
||||
|
@ -115,7 +122,8 @@ async function migrationV1ToV2(
|
|||
|
||||
async function migrationV2ToV3(
|
||||
exportDir: string,
|
||||
exportRecord: ExportRecordV2
|
||||
exportRecord: ExportRecordV2,
|
||||
updateProgress: (progress: ExportProgress) => void
|
||||
) {
|
||||
if (!exportRecord?.exportedFiles) {
|
||||
return;
|
||||
|
@ -134,7 +142,8 @@ async function migrationV2ToV3(
|
|||
|
||||
const fileExportNames = await getFileExportNamesFromExportedFiles(
|
||||
exportRecord,
|
||||
getExportedFiles(personalFiles, exportRecord)
|
||||
getExportedFiles(personalFiles, exportRecord),
|
||||
updateProgress
|
||||
);
|
||||
|
||||
exportRecord.exportedCollectionPaths = undefined;
|
||||
|
@ -264,7 +273,8 @@ async function getCollectionExportNamesFromExportedCollectionPaths(
|
|||
*/
|
||||
async function getFileExportNamesFromExportedFiles(
|
||||
exportRecord: ExportRecordV2,
|
||||
exportedFiles: EnteFile[]
|
||||
exportedFiles: EnteFile[],
|
||||
updateProgress: (progress: ExportProgress) => void
|
||||
): Promise<FileExportNames> {
|
||||
if (!exportedFiles.length) {
|
||||
return;
|
||||
|
@ -278,7 +288,9 @@ async function getFileExportNamesFromExportedFiles(
|
|||
const exportedCollectionPaths = convertCollectionIDFolderPathObjectToMap(
|
||||
exportRecord.exportedCollectionPaths
|
||||
);
|
||||
let success = 0;
|
||||
for (const file of exportedFiles) {
|
||||
await sleep(0);
|
||||
const collectionPath = exportedCollectionPaths.get(file.collectionID);
|
||||
addLocalLog(
|
||||
() =>
|
||||
|
@ -323,6 +335,11 @@ async function getFileExportNamesFromExportedFiles(
|
|||
...exportedFileNames,
|
||||
[getExportRecordFileUID(file)]: fileExportName,
|
||||
};
|
||||
updateProgress({
|
||||
total: exportedFiles.length,
|
||||
success: success++,
|
||||
failed: 0,
|
||||
});
|
||||
}
|
||||
return exportedFileNames;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue