1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +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 existingNote = fuzzyMatching ? await fuzzyMatch(note) : null;
let result = {
noteCreated: false,
noteUpdated: false,
resourcesCreated: 0,
};
if (existingNote) { if (existingNote) {
let diff = BaseModel.diffObjects(existingNote, note); let diff = BaseModel.diffObjects(existingNote, note);
delete diff.tags; delete diff.tags;
delete diff.resources; delete diff.resources;
delete diff.id; delete diff.id;
// console.info('======================================'); // TODO: also save resources
// console.info(note);
// console.info(existingNote);
// console.info(diff);
// console.info('======================================');
if (!Object.getOwnPropertyNames(diff).length) return; if (!Object.getOwnPropertyNames(diff).length) return;
diff.id = existingNote.id; diff.id = existingNote.id;
diff.type_ = existingNote.type_; diff.type_ = existingNote.type_;
return Note.save(diff, { autoTimestamp: false }); return Note.save(diff, { autoTimestamp: false }).then(() => {
result.noteUpdated = true;
return result;
});
} else { } else {
for (let i = 0; i < note.resources.length; i++) { for (let i = 0; i < note.resources.length; i++) {
let resource = note.resources[i]; let resource = note.resources[i];
@ -119,12 +124,16 @@ async function saveNoteToStorage(note, fuzzyMatching = false) {
if (existingResource) continue; if (existingResource) continue;
await Resource.save(toSave, { isNew: true }); 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, { return Note.save(note, {
isNew: true, isNew: true,
autoTimestamp: false, autoTimestamp: false,
}).then(() => {
result.noteCreated = true;
return result;
}); });
} }
} }
@ -138,7 +147,9 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let progressState = { let progressState = {
loaded: 0, loaded: 0,
imported: 0, created: 0,
updated: 0,
resourcesCreated: 0,
}; };
let stream = fs.createReadStream(filePath); let stream = fs.createReadStream(filePath);
@ -188,8 +199,13 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
note.body = body; note.body = body;
return saveNoteToStorage(note, importOptions.fuzzyMatching); return saveNoteToStorage(note, importOptions.fuzzyMatching);
}).then(() => { }).then((result) => {
progressState.imported++; if (result.noteUpdated) {
progressState.updated++;
} else if (result.noteCreated) {
progressState.created++;
}
progressState.resourcesCreated += result.resourcesCreated;
importOptions.onProgress(progressState); importOptions.onProgress(progressState);
}); });
}); });

View File

@ -348,9 +348,13 @@ commands.push({
let options = { let options = {
fuzzyMatching: args.options['fuzzy-matching'] === true, fuzzyMatching: args.options['fuzzy-matching'] === true,
onProgress: (progressState) => { 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; redrawnCalled = true;
vorpal.ui.redraw(line); vorpal.ui.redraw(line.join(' '));
}, },
onError: (error) => { onError: (error) => {
let s = error.trace ? error.trace : error.toString(); let s = error.trace ? error.trace : error.toString();