1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

More logging on import enex

This commit is contained in:
Laurent Cozic 2017-06-26 19:12:49 +00:00
parent 09c1d58358
commit 6aa7ea0c6c
2 changed files with 32 additions and 12 deletions

View File

@ -89,23 +89,28 @@ async function saveNoteToStorage(note, fuzzyMatching = false) {
let existingNote = fuzzyMatching ? await fuzzyMatch(note) : null;
let result = {
noteCreated: false,
noteUpdated: false,
resourcesCreated: 0,
};
if (existingNote) {
let diff = BaseModel.diffObjects(existingNote, note);
delete diff.tags;
delete diff.resources;
delete diff.id;
// console.info('======================================');
// console.info(note);
// console.info(existingNote);
// console.info(diff);
// console.info('======================================');
// TODO: also save resources
if (!Object.getOwnPropertyNames(diff).length) return;
diff.id = existingNote.id;
diff.type_ = existingNote.type_;
return Note.save(diff, { autoTimestamp: false });
return Note.save(diff, { autoTimestamp: false }).then(() => {
result.noteUpdated = true;
return result;
});
} else {
for (let i = 0; i < note.resources.length; i++) {
let resource = note.resources[i];
@ -119,12 +124,16 @@ async function saveNoteToStorage(note, fuzzyMatching = false) {
if (existingResource) continue;
await Resource.save(toSave, { isNew: true });
await filePutContents(Resource.fullPath(toSave), resource.data);
await filePutContents(Resource.fullPath(toSave), resource.data)
result.resourcesCreated++;
}
return Note.save(note, {
isNew: true,
autoTimestamp: false,
}).then(() => {
result.noteCreated = true;
return result;
});
}
}
@ -138,7 +147,9 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
return new Promise((resolve, reject) => {
let progressState = {
loaded: 0,
imported: 0,
created: 0,
updated: 0,
resourcesCreated: 0,
};
let stream = fs.createReadStream(filePath);
@ -188,8 +199,13 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
note.body = body;
return saveNoteToStorage(note, importOptions.fuzzyMatching);
}).then(() => {
progressState.imported++;
}).then((result) => {
if (result.noteUpdated) {
progressState.updated++;
} else if (result.noteCreated) {
progressState.created++;
}
progressState.resourcesCreated += result.resourcesCreated;
importOptions.onProgress(progressState);
});
});

View File

@ -348,9 +348,13 @@ commands.push({
let options = {
fuzzyMatching: args.options['fuzzy-matching'] === true,
onProgress: (progressState) => {
let line = sprintf(_('Found: %d. Imported: %d.', progressState.loaded, progressState.imported));
let line = [];
line.push(_('Found: %d.', progressState.loaded));
line.push(_('Created: %d.', progressState.created));
if (progressState.updated) line.push(_('Updated: %d.', progressState.updated));
if (progressState.resourcesCreated) line.push(_('Resources: %d.', progressState.resourcesCreated));
redrawnCalled = true;
vorpal.ui.redraw(line);
vorpal.ui.redraw(line.join(' '));
},
onError: (error) => {
let s = error.trace ? error.trace : error.toString();