add logs and fix issues
This commit is contained in:
parent
102f13d7e5
commit
6c15dca704
|
@ -173,7 +173,7 @@ export default function ExportModal(props: Props) {
|
|||
const exportRecord = await exportService.getExportRecord(
|
||||
exportFolder
|
||||
);
|
||||
if (!exportRecord) {
|
||||
if (!exportRecord?.stage) {
|
||||
setExportStage(ExportStage.INIT);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ import { FILE_TYPE, TYPE_JPEG, TYPE_JPG } from 'constants/file';
|
|||
import { ExportStage } from 'constants/export';
|
||||
import { ElectronAPIs } from 'types/electron';
|
||||
import { CustomError } from 'utils/error';
|
||||
import { addLogLine } from 'utils/logging';
|
||||
import { addLocalLog, addLogLine } from 'utils/logging';
|
||||
import { eventBus, Events } from './events';
|
||||
import { getCollectionNameMap } from 'utils/collection';
|
||||
|
||||
|
@ -244,9 +244,11 @@ class ExportService {
|
|||
const user: User = getData(LS_KEYS.USER);
|
||||
|
||||
const localFiles = await getLocalFiles();
|
||||
const userPersonalFiles = localFiles
|
||||
.filter((file) => file.ownerID === user?.id)
|
||||
.sort((fileA, fileB) => fileA.id - fileB.id);
|
||||
const userPersonalFiles = mergeMetadata(
|
||||
localFiles
|
||||
.filter((file) => file.ownerID === user?.id)
|
||||
.sort((fileA, fileB) => fileA.id - fileB.id)
|
||||
);
|
||||
|
||||
const collections = await getLocalCollections();
|
||||
const nonEmptyCollections = getNonEmptyCollections(
|
||||
|
@ -274,6 +276,7 @@ class ExportService {
|
|||
renamedCollections?.length > 0 &&
|
||||
this.checkAllElectronAPIsExists()
|
||||
) {
|
||||
addLogLine(`renaming ${renamedCollections.length} collections`);
|
||||
this.collectionRenamer(
|
||||
exportDir,
|
||||
collectionIDPathMap,
|
||||
|
@ -287,6 +290,9 @@ class ExportService {
|
|||
);
|
||||
|
||||
if (deletedExportedCollections?.length > 0) {
|
||||
addLogLine(
|
||||
`removing ${deletedExportedCollections.length} collections`
|
||||
);
|
||||
await this.collectionRemover(
|
||||
deletedExportedCollections,
|
||||
exportDir
|
||||
|
@ -299,6 +305,7 @@ class ExportService {
|
|||
);
|
||||
|
||||
if (filesToExport?.length > 0) {
|
||||
addLogLine(`exporting ${filesToExport.length} files`);
|
||||
await this.fileExporter(
|
||||
filesToExport,
|
||||
collectionIDNameMap,
|
||||
|
@ -311,7 +318,8 @@ class ExportService {
|
|||
exportRecord
|
||||
);
|
||||
|
||||
if (removedFileUIDs?.length) {
|
||||
if (removedFileUIDs?.length > 0) {
|
||||
addLogLine(`removing ${removedFileUIDs.length} files`);
|
||||
await this.fileRemover(removedFileUIDs, exportDir);
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -325,6 +333,10 @@ class ExportService {
|
|||
renamedCollections: Collection[]
|
||||
) {
|
||||
for (const collection of renamedCollections) {
|
||||
addLocalLog(
|
||||
() =>
|
||||
`renaming collection ${collection.name} with id ${collection.id}`
|
||||
);
|
||||
const oldCollectionFolderPath = collectionIDPathMap.get(
|
||||
collection.id
|
||||
);
|
||||
|
@ -357,6 +369,10 @@ class ExportService {
|
|||
exportRecord.exportedCollectionPaths
|
||||
);
|
||||
for (const collectionID of deletedExportedCollectionIDs) {
|
||||
addLocalLog(
|
||||
() =>
|
||||
`removing collection with id ${collectionID} from export folder`
|
||||
);
|
||||
const collectionFolderPath = collectionIDPathMap.get(collectionID);
|
||||
await this.electronAPIs.removeFolder(collectionFolderPath);
|
||||
await this.removeCollectionExportedRecord(
|
||||
|
@ -381,6 +397,14 @@ class ExportService {
|
|||
total: files.length,
|
||||
});
|
||||
for (const file of files) {
|
||||
addLocalLog(
|
||||
() =>
|
||||
`exporting file ${file.metadata.title} with id ${
|
||||
file.id
|
||||
} from collection ${collectionIDNameMap.get(
|
||||
file.collectionID
|
||||
)}`
|
||||
);
|
||||
if (this.stopExport) {
|
||||
break;
|
||||
}
|
||||
|
@ -445,6 +469,7 @@ class ExportService {
|
|||
exportRecord.exportedFilePaths
|
||||
);
|
||||
for (const fileUID of removedFileUIDs) {
|
||||
addLocalLog(() => `removing file with id ${fileUID}`);
|
||||
if (this.stopExport) {
|
||||
break;
|
||||
}
|
||||
|
@ -525,7 +550,7 @@ class ExportService {
|
|||
|
||||
exportRecord.exportedCollectionPaths = Object.fromEntries(
|
||||
Object.entries(exportRecord.exportedCollectionPaths).filter(
|
||||
([key]) => key === collectionID.toString()
|
||||
([key]) => key !== collectionID.toString()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -541,7 +566,7 @@ class ExportService {
|
|||
const exportRecord = await this.getExportRecord(folder);
|
||||
exportRecord.exportedFilePaths = Object.fromEntries(
|
||||
Object.entries(exportRecord.exportedFilePaths).filter(
|
||||
([key]) => key === fileUID
|
||||
([key]) => key !== fileUID
|
||||
)
|
||||
);
|
||||
await this.updateExportRecord(exportRecord, folder);
|
||||
|
@ -658,7 +683,6 @@ class ExportService {
|
|||
collectionPath: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
file.metadata = mergeMetadata([file])[0].metadata;
|
||||
const fileSaveName = getUniqueFileSaveName(
|
||||
collectionPath,
|
||||
file.metadata.title,
|
||||
|
|
|
@ -13,6 +13,7 @@ import { splitFilenameAndExtension } from 'utils/file';
|
|||
import { ENTE_METADATA_FOLDER } from 'constants/export';
|
||||
import sanitize from 'sanitize-filename';
|
||||
import { formatDateTimeShort } from 'utils/time/format';
|
||||
import { addLocalLog } from 'utils/logging';
|
||||
|
||||
export const getExportRecordFileUID = (file: EnteFile) =>
|
||||
`${file.id}_${file.collectionID}_${file.updationTime}`;
|
||||
|
@ -21,10 +22,11 @@ export const getCollectionsCreatedAfterLastExport = (
|
|||
collections: Collection[],
|
||||
exportRecord: ExportRecord
|
||||
) => {
|
||||
if (!exportRecord?.exportedCollectionPaths) {
|
||||
return collections;
|
||||
}
|
||||
const exportedCollections = new Set(
|
||||
Object.keys(exportRecord?.exportedCollectionPaths ?? {}).map((x) =>
|
||||
Number(x)
|
||||
)
|
||||
Object.keys(exportRecord?.exportedCollectionPaths).map((x) => Number(x))
|
||||
);
|
||||
const unExportedCollections = collections.filter((collection) => {
|
||||
if (!exportedCollections.has(collection.id)) {
|
||||
|
@ -85,8 +87,19 @@ export const getDeletedExportedCollections = (
|
|||
exportRecord: ExportRecord
|
||||
) => {
|
||||
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) {
|
||||
return [];
|
||||
}
|
||||
const deletedExportedCollections = Object.keys(
|
||||
exportRecord?.exportedCollectionPaths
|
||||
)
|
||||
|
@ -121,6 +134,9 @@ export const getExportedFiles = (
|
|||
allFiles: EnteFile[],
|
||||
exportRecord: ExportRecord
|
||||
) => {
|
||||
if (!exportRecord?.exportedFilePaths) {
|
||||
return [];
|
||||
}
|
||||
const exportedFileIds = new Set(
|
||||
Object.keys(exportRecord?.exportedFilePaths)
|
||||
);
|
||||
|
@ -140,6 +156,9 @@ export const getDeletedExportedFiles = (
|
|||
const presentFileUIDs = new Set(
|
||||
allFiles?.map((file) => getExportRecordFileUID(file))
|
||||
);
|
||||
if (!exportRecord?.exportedFilePaths) {
|
||||
return [];
|
||||
}
|
||||
const deletedExportedFiles = Object.keys(
|
||||
exportRecord?.exportedFilePaths
|
||||
).filter((fileUID) => {
|
||||
|
|
Loading…
Reference in a new issue