mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
Change method when adding a new note.
Add reference to new backend method
This commit is contained in:
parent
bbe3f436d3
commit
8394ce8002
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const attributeService = require("../../services/attributes");
|
const attributeService = require("../../services/attributes");
|
||||||
|
const cloneService = require("../../services/cloning");
|
||||||
const noteService = require('../../services/notes');
|
const noteService = require('../../services/notes');
|
||||||
const dateNoteService = require('../../services/date_notes');
|
const dateNoteService = require('../../services/date_notes');
|
||||||
const dateUtils = require('../../services/date_utils');
|
const dateUtils = require('../../services/date_utils');
|
||||||
@ -24,7 +25,7 @@ function findClippingNote(clipperInboxNote, pageUrl) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
if (note.getOwnedLabelValue('clipType') === 'clippings') {
|
if (note.getOwnedLabelValue('clipType') === 'note') {
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,16 +44,20 @@ function getClipperInboxNote() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addClipping(req) {
|
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;
|
let {title, content, pageUrl, images} = req.body;
|
||||||
|
|
||||||
const clipperInbox = getClipperInboxNote();
|
const clipperInbox = getClipperInboxNote();
|
||||||
|
|
||||||
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({
|
||||||
parentNoteId: clipperInbox.noteId,
|
parentNoteId: dailyNote.noteId,
|
||||||
title: title,
|
title: title,
|
||||||
content: '',
|
content: '',
|
||||||
type: 'text'
|
type: 'text'
|
||||||
@ -63,12 +68,16 @@ function addClipping(req) {
|
|||||||
clippingNote.setLabel('iconClass', 'bx bx-globe');
|
clippingNote.setLabel('iconClass', 'bx bx-globe');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const rewrittenContent = processContent(images, clippingNote, content);
|
const rewrittenContent = processContent(images, clippingNote, content);
|
||||||
|
|
||||||
const existingContent = clippingNote.getContent();
|
const existingContent = clippingNote.getContent();
|
||||||
|
|
||||||
clippingNote.setContent(`${existingContent}${existingContent.trim() ? "<br/>" : ""}${rewrittenContent}`);
|
clippingNote.setContent(`${existingContent}${existingContent.trim() ? "<br/>" : ""}${rewrittenContent}`);
|
||||||
|
|
||||||
|
if (clippingNote.parentNoteId != dailyNote.noteId){
|
||||||
|
cloneService.cloneNoteToParentNote(clippingNote.noteId, dailyNote.noteId);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
noteId: clippingNote.noteId
|
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 = {
|
module.exports = {
|
||||||
createNote,
|
createNote,
|
||||||
addClipping,
|
addClipping,
|
||||||
openNote,
|
openNote,
|
||||||
handshake
|
handshake,
|
||||||
|
findNotesByUrl
|
||||||
};
|
};
|
||||||
|
@ -286,6 +286,7 @@ function register(app) {
|
|||||||
route(POST, '/api/clipper/clippings', clipperMiddleware, clipperRoute.addClipping, apiResultHandler);
|
route(POST, '/api/clipper/clippings', clipperMiddleware, clipperRoute.addClipping, apiResultHandler);
|
||||||
route(POST, '/api/clipper/notes', clipperMiddleware, clipperRoute.createNote, apiResultHandler);
|
route(POST, '/api/clipper/notes', clipperMiddleware, clipperRoute.createNote, apiResultHandler);
|
||||||
route(POST, '/api/clipper/open/:noteId', clipperMiddleware, clipperRoute.openNote, 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);
|
apiRoute(GET, '/api/similar-notes/:noteId', similarNotesRoute.getSimilarNotes);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user