From 8394ce800270d5b843fcc4cea22319420c9c8dff Mon Sep 17 00:00:00 2001 From: manto89 Date: Wed, 21 Jun 2023 13:09:49 +0200 Subject: [PATCH] Change method when adding a new note. Add reference to new backend method --- src/routes/api/clipper.js | 30 +++++++++++++++++++++++++----- src/routes/routes.js | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index d792ff38a..6cf03a519 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -1,6 +1,7 @@ "use strict"; const attributeService = require("../../services/attributes"); +const cloneService = require("../../services/cloning"); const noteService = require('../../services/notes'); const dateNoteService = require('../../services/date_notes'); const dateUtils = require('../../services/date_utils'); @@ -24,7 +25,7 @@ function findClippingNote(clipperInboxNote, pageUrl) { ); for (const note of notes) { - if (note.getOwnedLabelValue('clipType') === 'clippings') { + if (note.getOwnedLabelValue('clipType') === 'note') { return note; } } @@ -43,16 +44,20 @@ function getClipperInboxNote() { } function addClipping(req) { + //if a note under the clipperInbox as the same 'pageUrl' attribute, add the content to that note + //and clone it under today's inbox + //otherwise just create a new note under today's inbox let {title, content, pageUrl, images} = req.body; const clipperInbox = getClipperInboxNote(); pageUrl = htmlSanitizer.sanitizeUrl(pageUrl); let clippingNote = findClippingNote(clipperInbox, pageUrl); - + let dailyNote = dateNoteService.getDayNote(dateUtils.localNowDate()); + if (!clippingNote) { clippingNote = noteService.createNewNote({ - parentNoteId: clipperInbox.noteId, + parentNoteId: dailyNote.noteId, title: title, content: '', type: 'text' @@ -63,12 +68,16 @@ function addClipping(req) { clippingNote.setLabel('iconClass', 'bx bx-globe'); } + const rewrittenContent = processContent(images, clippingNote, content); const existingContent = clippingNote.getContent(); clippingNote.setContent(`${existingContent}${existingContent.trim() ? "
" : ""}${rewrittenContent}`); - + + if (clippingNote.parentNoteId != dailyNote.noteId){ + cloneService.cloneNoteToParentNote(clippingNote.noteId, dailyNote.noteId); + } return { noteId: clippingNote.noteId }; @@ -187,9 +196,20 @@ function handshake() { } } +function findNotesByUrl(req){ + let pageUrl = req.params.noteUrl; + const clipperInbox = getClipperInboxNote(); + let foundPage = findClippingNote(clipperInbox, pageUrl); + return { + noteId: foundPage ? foundPage.noteId : null + } + +} + module.exports = { createNote, addClipping, openNote, - handshake + handshake, + findNotesByUrl }; diff --git a/src/routes/routes.js b/src/routes/routes.js index 2989208b5..764b2746c 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -286,6 +286,7 @@ function register(app) { route(POST, '/api/clipper/clippings', clipperMiddleware, clipperRoute.addClipping, apiResultHandler); route(POST, '/api/clipper/notes', clipperMiddleware, clipperRoute.createNote, apiResultHandler); route(POST, '/api/clipper/open/:noteId', clipperMiddleware, clipperRoute.openNote, apiResultHandler); + route(GET, '/api/clipper/notes-by-url/:noteUrl', clipperMiddleware, clipperRoute.findNotesByUrl, apiResultHandler); apiRoute(GET, '/api/similar-notes/:noteId', similarNotesRoute.getSimilarNotes);