From 139c99440fb8a101ec0a469daab30cfb7f80cb8b Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 26 Nov 2018 23:39:43 +0100 Subject: [PATCH] export stores note position and some other fixes --- src/services/export/tar.js | 1 + src/services/import/tar.js | 31 ++++++++++++++++++++++++++----- src/services/notes.js | 12 ++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/services/export/tar.js b/src/services/export/tar.js index e65044d17..8d8561968 100644 --- a/src/services/export/tar.js +++ b/src/services/export/tar.js @@ -87,6 +87,7 @@ async function exportToTar(branch, format, res) { isClone: false, noteId: note.noteId, title: note.title, + notePosition: branch.notePosition, prefix: branch.prefix, isExpanded: branch.isExpanded, type: note.type, diff --git a/src/services/import/tar.js b/src/services/import/tar.js index 1ab21807a..8170274a4 100644 --- a/src/services/import/tar.js +++ b/src/services/import/tar.js @@ -47,7 +47,7 @@ async function importTar(fileBuffer, importRootNote) { function getMeta(filePath) { if (!metaFile) { - return; + return {}; } const pathSegments = filePath.split(/[\/\\]/g); @@ -83,11 +83,14 @@ async function importTar(fileBuffer, importRootNote) { else { const parentPath = path.dirname(filePath); - if (parentPath in createdPaths) { + if (parentPath === '.') { + parentNoteId = importRootNote.noteId; + } + else if (parentPath in createdPaths) { parentNoteId = createdPaths[parentPath]; } else { - throw new Error(`Could not find existing path ${parentPath}.`); + throw new Error(`Could not find existing path ${parentPath} for ${filePath}.`); } } @@ -212,7 +215,8 @@ async function importTar(fileBuffer, importRootNote) { noteId, parentNoteId, isExpanded: noteMeta.isExpanded, - prefix: noteMeta.prefix + prefix: noteMeta.prefix, + notePosition: noteMeta.notePosition }).save(); return; @@ -252,11 +256,28 @@ async function importTar(fileBuffer, importRootNote) { type, mime, prefix: noteMeta ? noteMeta.prefix : '', - isExpanded: noteMeta ? noteMeta.isExpanded : false + isExpanded: noteMeta ? noteMeta.isExpanded : false, + notePosition: noteMeta ? noteMeta.notePosition : false })); await saveAttributesAndLinks(note, noteMeta); + if (!noteMeta && (type === 'file' || type === 'image')) { + attributes.push({ + noteId, + type: 'label', + name: 'originalFileName', + value: path.basename(filePath) + }); + + attributes.push({ + noteId, + type: 'label', + name: 'fileSize', + value: content.byteLength + }); + } + if (!firstNote) { firstNote = note; } diff --git a/src/services/notes.js b/src/services/notes.js index e4d2ed664..34f578020 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -49,7 +49,14 @@ async function triggerNoteTitleChanged(note) { * FIXME: noteData has mandatory property "target", it might be better to add it as parameter to reflect this */ async function createNewNote(parentNoteId, noteData) { - const newNotePos = await getNewNotePosition(parentNoteId, noteData); + let newNotePos; + + if (noteData.notePosition !== undefined) { + newNotePos = noteData.notePosition; + } + else { + newNotePos = await getNewNotePosition(parentNoteId, noteData); + } const parentNote = await repository.getNote(parentNoteId); @@ -130,7 +137,8 @@ async function createNote(parentNoteId, title, content = "", extraOptions = {}) type: extraOptions.type, mime: extraOptions.mime, dateCreated: extraOptions.dateCreated, - isExpanded: extraOptions.isExpanded + isExpanded: extraOptions.isExpanded, + notePosition: extraOptions.notePosition }; if (extraOptions.json && !noteData.type) {