refactoring of note creation APIs WIP

This commit is contained in:
zadam
2019-11-16 11:09:52 +01:00
parent de02e9e889
commit 13c0411533
13 changed files with 115 additions and 107 deletions

View File

@@ -30,7 +30,10 @@ async function importEnex(taskContext, file, parentNote) {
: file.originalname;
// root note is new note into all ENEX/notebook's notes will be imported
const rootNote = (await noteService.createNote(parentNote.noteId, rootNoteTitle, "", {
const rootNote = (await noteService.createNewNote({
parentNoteId: parentNote.noteId,
title: rootNoteTitle,
content: "",
type: 'text',
mime: 'text/html',
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
@@ -207,14 +210,20 @@ async function importEnex(taskContext, file, parentNote) {
// following is workaround for this issue: https://github.com/Leonidas-from-XIV/node-xml2js/issues/484
content = extractContent(xmlObject['en-note']);
const noteEntity = (await noteService.createNote(rootNote.noteId, title, content, {
attributes,
const noteEntity = (await noteService.createNewNote({
parentNoteId: rootNote.noteId,
title,
content,
utcDateCreated,
type: 'text',
mime: 'text/html',
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
})).note;
for (const attr of resource.attributes) {
await note.addAttribute(attr.type, attr.name, attr.value);
}
taskContext.increaseProgressCount();
let noteContent = await noteEntity.getContent();
@@ -231,13 +240,19 @@ async function importEnex(taskContext, file, parentNote) {
}
const createFileNote = async () => {
const resourceNote = (await noteService.createNote(noteEntity.noteId, resource.title, resource.content, {
attributes: resource.attributes,
const resourceNote = (await noteService.createNewNote({
parentNoteId: noteEntity.noteId,
title: resource.title,
content: resource.content,
type: 'file',
mime: resource.mime,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
})).note;
for (const attr of resource.attributes) {
await note.addAttribute(attr.type, attr.name, attr.value);
}
taskContext.increaseProgressCount();
const resourceLink = `<a href="#root/${resourceNote.noteId}">${utils.escapeHtml(resource.title)}</a>`;

View File

@@ -44,8 +44,11 @@ async function importOpml(taskContext, fileBuffer, parentNote) {
throw new Error("Unrecognized OPML version " + opmlVersion);
}
const {note} = await noteService.createNote(parentNoteId, title, content, {
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
const {note} = await noteService.createNewNote({
parentNoteId,
title,
content,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable()
});
taskContext.increaseProgressCount();

View File

@@ -41,16 +41,18 @@ async function importImage(file, parentNote, taskContext) {
async function importFile(taskContext, file, parentNote) {
const originalName = file.originalname;
const size = file.size;
const {note} = await noteService.createNote(parentNote.noteId, originalName, file.buffer, {
target: 'into',
const {note} = await noteService.createNewNote({
parentNoteId: parentNote.noteId,
title: originalName,
content: file.buffer,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
type: 'file',
mime: mimeService.getMime(originalName) || file.mimetype,
attributes: [{ type: "label", name: "originalFileName", value: originalName }]
mime: mimeService.getMime(originalName) || file.mimetype
});
await note.addLabel("originalFileName", originalName);
taskContext.increaseProgressCount();
return note;
@@ -62,7 +64,10 @@ async function importCodeNote(taskContext, file, parentNote) {
const detectedMime = mimeService.getMime(file.originalname) || file.mimetype;
const mime = mimeService.normalizeMimeType(detectedMime);
const {note} = await noteService.createNote(parentNote.noteId, title, content, {
const {note} = await noteService.createNewNote({
parentNoteId: parentNote.noteId,
title,
content,
type: 'code',
mime: mime,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable()
@@ -78,7 +83,10 @@ async function importPlainText(taskContext, file, parentNote) {
const plainTextContent = file.buffer.toString("UTF-8");
const htmlContent = convertTextToHtml(plainTextContent);
const {note} = await noteService.createNote(parentNote.noteId, title, htmlContent, {
const {note} = await noteService.createNewNote({
parentNoteId: parentNote.noteId,
title,
content: htmlContent,
type: 'text',
mime: 'text/html',
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
@@ -118,7 +126,10 @@ async function importMarkdown(taskContext, file, parentNote) {
const title = getFileNameWithoutExtension(file.originalname);
const {note} = await noteService.createNote(parentNote.noteId, title, htmlContent, {
const {note} = await noteService.createNewNote({
parentNoteId: parentNote.noteId,
title,
content: htmlContent,
type: 'text',
mime: 'text/html',
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
@@ -133,7 +144,10 @@ async function importHtml(taskContext, file, parentNote) {
const title = getFileNameWithoutExtension(file.originalname);
const content = file.buffer.toString("UTF-8");
const {note} = await noteService.createNote(parentNote.noteId, title, content, {
const {note} = await noteService.createNewNote({
parentNoteId: parentNote.noteId,
title,
content,
type: 'text',
mime: 'text/html',
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),

View File

@@ -177,8 +177,11 @@ async function importTar(taskContext, fileBuffer, importRootNote) {
return;
}
({note} = await noteService.createNote(parentNoteId, noteTitle, '', {
noteId,
({note} = await noteService.createNewNote({
parentNoteId: parentNoteId,
title: noteTitle,
content: '',
noteId: noteId,
type: noteMeta ? noteMeta.type : 'text',
mime: noteMeta ? noteMeta.mime : 'text/html',
prefix: noteMeta ? noteMeta.prefix : '',
@@ -324,7 +327,10 @@ async function importTar(taskContext, fileBuffer, importRootNote) {
await note.setContent(content);
}
else {
({note} = await noteService.createNote(parentNoteId, noteTitle, content, {
({note} = await noteService.createNewNote({
parentNoteId: parentNoteId,
title: noteTitle,
content: content,
noteId,
type,
mime,