Tinker
This commit is contained in:
parent
73292a5405
commit
c2c5267e9b
2 changed files with 20 additions and 46 deletions
|
@ -364,15 +364,14 @@ class UploadManager {
|
|||
uploaderName?: string,
|
||||
) {
|
||||
try {
|
||||
if (this.uploadInProgress) {
|
||||
throw Error("can't run multiple uploads at once");
|
||||
}
|
||||
if (this.uploadInProgress)
|
||||
throw new Error("Cannot run multiple uploads at once");
|
||||
|
||||
log.info(`Uploading ${filesWithCollectionToUploadIn.length} files`);
|
||||
this.uploadInProgress = true;
|
||||
await this.updateExistingFilesAndCollections(collections);
|
||||
this.uploaderName = uploaderName;
|
||||
log.info(
|
||||
`received ${filesWithCollectionToUploadIn.length} files to upload`,
|
||||
);
|
||||
|
||||
this.uiService.setFilenames(
|
||||
new Map<number, string>(
|
||||
filesWithCollectionToUploadIn.map((mediaFile) => [
|
||||
|
@ -381,10 +380,10 @@ class UploadManager {
|
|||
]),
|
||||
),
|
||||
);
|
||||
|
||||
const { metadataJSONFiles, mediaFiles } =
|
||||
segregateMetadataAndMediaFiles(filesWithCollectionToUploadIn);
|
||||
log.info(`has ${metadataJSONFiles.length} metadata json files`);
|
||||
log.info(`has ${mediaFiles.length} media files`);
|
||||
|
||||
if (metadataJSONFiles.length) {
|
||||
this.uiService.setUploadStage(
|
||||
UPLOAD_STAGES.READING_GOOGLE_METADATA_FILES,
|
||||
|
@ -458,44 +457,21 @@ class UploadManager {
|
|||
};
|
||||
|
||||
private async parseMetadataJSONFiles(metadataFiles: FileWithCollection2[]) {
|
||||
try {
|
||||
log.info(`parseMetadataJSONFiles function executed `);
|
||||
this.uiService.reset(metadataFiles.length);
|
||||
|
||||
this.uiService.reset(metadataFiles.length);
|
||||
for (const { file, collectionID } of metadataFiles) {
|
||||
this.abortIfCancelled();
|
||||
|
||||
for (const { file, collectionID } of metadataFiles) {
|
||||
this.abortIfCancelled();
|
||||
const name = getFileName(file);
|
||||
try {
|
||||
log.info(`parsing metadata json file ${name}`);
|
||||
|
||||
const metadataJSON =
|
||||
await tryParseTakeoutMetadataJSON(file);
|
||||
if (metadataJSON) {
|
||||
this.parsedMetadataJSONMap.set(
|
||||
getMetadataJSONMapKeyForJSON(collectionID, name),
|
||||
metadataJSON && { ...metadataJSON },
|
||||
);
|
||||
this.uiService.increaseFileUploaded();
|
||||
}
|
||||
log.info(`successfully parsed metadata json file ${name}`);
|
||||
} catch (e) {
|
||||
if (e.message === CustomError.UPLOAD_CANCELLED) {
|
||||
throw e;
|
||||
} else {
|
||||
// and don't break for subsequent files just log and move on
|
||||
log.error("parsing failed for a file", e);
|
||||
log.info(
|
||||
`failed to parse metadata json file ${name} error: ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const fileName = getFileName(file);
|
||||
log.info(`Parsing metadata JSON ${fileName}`);
|
||||
const metadataJSON = await tryParseTakeoutMetadataJSON(file);
|
||||
if (metadataJSON) {
|
||||
this.parsedMetadataJSONMap.set(
|
||||
getMetadataJSONMapKeyForJSON(collectionID, fileName),
|
||||
metadataJSON,
|
||||
);
|
||||
this.uiService.increaseFileUploaded();
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.message !== CustomError.UPLOAD_CANCELLED) {
|
||||
log.error("error seeding MetadataMap", e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ import isElectron from "is-electron";
|
|||
import { exportMetadataDirectoryName } from "services/export";
|
||||
import { FileWithCollection, type FileWithCollection2 } from "types/upload";
|
||||
|
||||
const TYPE_JSON = "json";
|
||||
|
||||
export const hasFileHash = (file: Metadata) =>
|
||||
file.hash || (file.imageHash && file.videoHash);
|
||||
|
||||
|
@ -18,7 +16,7 @@ export function segregateMetadataAndMediaFiles(
|
|||
const mediaFiles: FileWithCollection[] = [];
|
||||
filesWithCollectionToUpload.forEach((fileWithCollection) => {
|
||||
const file = fileWithCollection.file;
|
||||
if (file.name.toLowerCase().endsWith(TYPE_JSON)) {
|
||||
if (file.name.toLowerCase().endsWith("json")) {
|
||||
metadataJSONFiles.push(fileWithCollection);
|
||||
} else {
|
||||
mediaFiles.push(fileWithCollection);
|
||||
|
|
Loading…
Add table
Reference in a new issue