Normalize behaviour with the other create method for web-clipper

This commit is contained in:
manto89 2023-06-21 16:10:06 +02:00
parent 8394ce8002
commit 54065672aa

View File

@ -37,7 +37,7 @@ function getClipperInboxNote() {
let clipperInbox = attributeService.getNoteWithLabel('clipperInbox'); let clipperInbox = attributeService.getNoteWithLabel('clipperInbox');
if (!clipperInbox) { if (!clipperInbox) {
clipperInbox = dateNoteService.getDayNote(dateUtils.localNowDate()); clipperInbox = dateNoteService.getRootCalendarNote();
} }
return clipperInbox; return clipperInbox;
@ -49,11 +49,12 @@ function addClipping(req) {
//otherwise just create a new note under today's inbox //otherwise just create a new note under today's inbox
let {title, content, pageUrl, images} = req.body; let {title, content, pageUrl, images} = req.body;
//this is only for reference
const clipperInbox = getClipperInboxNote(); const clipperInbox = getClipperInboxNote();
const dailyNote = dateNoteService.getDayNote(dateUtils.localNowDate());
pageUrl = htmlSanitizer.sanitizeUrl(pageUrl); pageUrl = htmlSanitizer.sanitizeUrl(pageUrl);
let clippingNote = findClippingNote(clipperInbox, pageUrl); let clippingNote = findClippingNote(clipperInbox, pageUrl);
let dailyNote = dateNoteService.getDayNote(dateUtils.localNowDate());
if (!clippingNote) { if (!clippingNote) {
clippingNote = noteService.createNewNote({ clippingNote = noteService.createNewNote({
@ -91,18 +92,20 @@ function createNote(req) {
} }
const clipperInbox = getClipperInboxNote(); const clipperInbox = getClipperInboxNote();
const dailyNote = dateNoteService.getDayNote(dateUtils.localNowDate());
pageUrl = htmlSanitizer.sanitizeUrl(pageUrl);
let note = findClippingNote(clipperInbox, pageUrl);
const {note} = noteService.createNewNote({ if (!note){
parentNoteId: clipperInbox.noteId, note = noteService.createNewNote({
parentNoteId: dailyNote.noteId,
title, title,
content, content,
type: 'text' type: 'text'
}); }).note;
clipType = htmlSanitizer.sanitize(clipType); clipType = htmlSanitizer.sanitize(clipType);
note.setLabel('clipType', clipType); note.setLabel('clipType', clipType);
if (pageUrl) { if (pageUrl) {
pageUrl = htmlSanitizer.sanitizeUrl(pageUrl); pageUrl = htmlSanitizer.sanitizeUrl(pageUrl);
@ -110,6 +113,11 @@ function createNote(req) {
note.setLabel('iconClass', 'bx bx-globe'); note.setLabel('iconClass', 'bx bx-globe');
} }
}
if (labels) { if (labels) {
for (const labelName in labels) { for (const labelName in labels) {
const labelValue = htmlSanitizer.sanitize(labels[labelName]); const labelValue = htmlSanitizer.sanitize(labels[labelName]);
@ -117,9 +125,11 @@ function createNote(req) {
} }
} }
const existingContent = note.getContent();
const rewrittenContent = processContent(images, note, content); const rewrittenContent = processContent(images, note, content);
note.setContent(`${existingContent}${existingContent.trim() ? "<br/>" : ""}${rewrittenContent}`);
note.setContent(rewrittenContent); // note.setContent(rewrittenContent);
return { return {
noteId: note.noteId noteId: note.noteId