mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	server-ts: Convert routes/api/bnote
This commit is contained in:
		
							parent
							
								
									40ef533c5f
								
							
						
					
					
						commit
						f98f84d419
					
				@ -1434,7 +1434,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
 | 
				
			|||||||
    searchNotesInSubtree(searchString: string) {
 | 
					    searchNotesInSubtree(searchString: string) {
 | 
				
			||||||
        const searchService = require('../../services/search/services/search');
 | 
					        const searchService = require('../../services/search/services/search');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return searchService.searchNotes(searchString);
 | 
					        return searchService.searchNotes(searchString) as BNote[];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    searchNoteInSubtree(searchString: string) {
 | 
					    searchNoteInSubtree(searchString: string) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,22 +1,32 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const attributeService = require('../../services/attributes');
 | 
					import { Request } from "express";
 | 
				
			||||||
const cloneService = require('../../services/cloning');
 | 
					
 | 
				
			||||||
const noteService = require('../../services/notes');
 | 
					import attributeService = require('../../services/attributes');
 | 
				
			||||||
const dateNoteService = require('../../services/date_notes');
 | 
					import cloneService = require('../../services/cloning');
 | 
				
			||||||
const dateUtils = require('../../services/date_utils');
 | 
					import noteService = require('../../services/notes');
 | 
				
			||||||
const imageService = require('../../services/image');
 | 
					import dateNoteService = require('../../services/date_notes');
 | 
				
			||||||
const appInfo = require('../../services/app_info');
 | 
					import dateUtils = require('../../services/date_utils');
 | 
				
			||||||
const ws = require('../../services/ws');
 | 
					import imageService = require('../../services/image');
 | 
				
			||||||
const log = require('../../services/log');
 | 
					import appInfo = require('../../services/app_info');
 | 
				
			||||||
const utils = require('../../services/utils');
 | 
					import ws = require('../../services/ws');
 | 
				
			||||||
const path = require('path');
 | 
					import log = require('../../services/log');
 | 
				
			||||||
const htmlSanitizer = require('../../services/html_sanitizer');
 | 
					import utils = require('../../services/utils');
 | 
				
			||||||
const {formatAttrForSearch} = require('../../services/attribute_formatter');
 | 
					import path = require('path');
 | 
				
			||||||
const jsdom = require("jsdom");
 | 
					import htmlSanitizer = require('../../services/html_sanitizer');
 | 
				
			||||||
 | 
					import attributeFormatter = require('../../services/attribute_formatter');
 | 
				
			||||||
 | 
					import jsdom = require("jsdom");
 | 
				
			||||||
 | 
					import BNote = require("../../becca/entities/bnote");
 | 
				
			||||||
 | 
					import ValidationError = require("../../errors/validation_error");
 | 
				
			||||||
const { JSDOM } = jsdom;
 | 
					const { JSDOM } = jsdom;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function addClipping(req) {
 | 
					interface Image {
 | 
				
			||||||
 | 
					    src: string;
 | 
				
			||||||
 | 
					    dataUrl: string;
 | 
				
			||||||
 | 
					    imageId: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function addClipping(req: Request) {
 | 
				
			||||||
    // if a note under the clipperInbox has the same 'pageUrl' attribute,
 | 
					    // if a note under the clipperInbox has the same 'pageUrl' attribute,
 | 
				
			||||||
    // add the content to that note and clone it under today's inbox
 | 
					    // add the content to that note and clone it under today's inbox
 | 
				
			||||||
    // otherwise just create a new note under today's inbox
 | 
					    // otherwise just create a new note under today's inbox
 | 
				
			||||||
@ -44,10 +54,14 @@ function addClipping(req) {
 | 
				
			|||||||
    const rewrittenContent = processContent(images, clippingNote, content);
 | 
					    const rewrittenContent = processContent(images, clippingNote, content);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const existingContent = clippingNote.getContent();
 | 
					    const existingContent = clippingNote.getContent();
 | 
				
			||||||
 | 
					    if (typeof existingContent !== "string") {
 | 
				
			||||||
 | 
					        throw new ValidationError("Invalid note content type.");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    clippingNote.setContent(`${existingContent}${existingContent.trim() ? "<br>" : ""}${rewrittenContent}`);
 | 
					    clippingNote.setContent(`${existingContent}${existingContent.trim() ? "<br>" : ""}${rewrittenContent}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (clippingNote.parentNoteId !== clipperInbox.noteId) {
 | 
					    // TODO: Is parentNoteId ever defined?
 | 
				
			||||||
 | 
					    if ((clippingNote as any).parentNoteId !== clipperInbox.noteId) {
 | 
				
			||||||
        cloneService.cloneNoteToParentNote(clippingNote.noteId, clipperInbox.noteId);
 | 
					        cloneService.cloneNoteToParentNote(clippingNote.noteId, clipperInbox.noteId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -56,13 +70,13 @@ function addClipping(req) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function findClippingNote(clipperInboxNote, pageUrl, clipType) {
 | 
					function findClippingNote(clipperInboxNote: BNote, pageUrl: string, clipType: string | null) {
 | 
				
			||||||
    if (!pageUrl) {
 | 
					    if (!pageUrl) {
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const notes = clipperInboxNote.searchNotesInSubtree(
 | 
					    const notes = clipperInboxNote.searchNotesInSubtree(
 | 
				
			||||||
        formatAttrForSearch({
 | 
					        attributeFormatter.formatAttrForSearch({
 | 
				
			||||||
            type: 'label',
 | 
					            type: 'label',
 | 
				
			||||||
            name: "pageUrl",
 | 
					            name: "pageUrl",
 | 
				
			||||||
            value: pageUrl
 | 
					            value: pageUrl
 | 
				
			||||||
@ -84,7 +98,7 @@ function getClipperInboxNote() {
 | 
				
			|||||||
    return clipperInbox;
 | 
					    return clipperInbox;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function createNote(req) {
 | 
					function createNote(req: Request) {
 | 
				
			||||||
    let {title, content, pageUrl, images, clipType, labels} = req.body;
 | 
					    let {title, content, pageUrl, images, clipType, labels} = req.body;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!title || !title.trim()) {
 | 
					    if (!title || !title.trim()) {
 | 
				
			||||||
@ -123,6 +137,9 @@ function createNote(req) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const existingContent = note.getContent();
 | 
					    const existingContent = note.getContent();
 | 
				
			||||||
 | 
					    if (typeof existingContent !== "string") {
 | 
				
			||||||
 | 
					        throw new ValidationError("Invalid note content tpye.");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    const rewrittenContent = processContent(images, note, content);
 | 
					    const rewrittenContent = processContent(images, note, content);
 | 
				
			||||||
    const newContent = `${existingContent}${existingContent.trim() ? "<br/>" : ""}${rewrittenContent}`;
 | 
					    const newContent = `${existingContent}${existingContent.trim() ? "<br/>" : ""}${rewrittenContent}`;
 | 
				
			||||||
    note.setContent(newContent);
 | 
					    note.setContent(newContent);
 | 
				
			||||||
@ -134,7 +151,7 @@ function createNote(req) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function processContent(images, note, content) {
 | 
					function processContent(images: Image[], note: BNote, content: string) {
 | 
				
			||||||
    let rewrittenContent = htmlSanitizer.sanitize(content);
 | 
					    let rewrittenContent = htmlSanitizer.sanitize(content);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (images) {
 | 
					    if (images) {
 | 
				
			||||||
@ -178,7 +195,7 @@ function processContent(images, note, content) {
 | 
				
			|||||||
    return rewrittenContent;
 | 
					    return rewrittenContent;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function openNote(req) {
 | 
					function openNote(req: Request) {
 | 
				
			||||||
    if (utils.isElectron()) {
 | 
					    if (utils.isElectron()) {
 | 
				
			||||||
        ws.sendMessageToAllClients({
 | 
					        ws.sendMessageToAllClients({
 | 
				
			||||||
            type: 'openNote',
 | 
					            type: 'openNote',
 | 
				
			||||||
@ -203,7 +220,7 @@ function handshake() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function findNotesByUrl(req){
 | 
					function findNotesByUrl(req: Request){
 | 
				
			||||||
    let pageUrl = req.params.noteUrl;
 | 
					    let pageUrl = req.params.noteUrl;
 | 
				
			||||||
    const clipperInbox = getClipperInboxNote();
 | 
					    const clipperInbox = getClipperInboxNote();
 | 
				
			||||||
    let foundPage = findClippingNote(clipperInbox, pageUrl, null);
 | 
					    let foundPage = findClippingNote(clipperInbox, pageUrl, null);
 | 
				
			||||||
@ -50,7 +50,7 @@ const searchRoute = require('./api/search');
 | 
				
			|||||||
const bulkActionRoute = require('./api/bulk_action');
 | 
					const bulkActionRoute = require('./api/bulk_action');
 | 
				
			||||||
const specialNotesRoute = require('./api/special_notes');
 | 
					const specialNotesRoute = require('./api/special_notes');
 | 
				
			||||||
const noteMapRoute = require('./api/note_map.js');
 | 
					const noteMapRoute = require('./api/note_map.js');
 | 
				
			||||||
const clipperRoute = require('./api/clipper.js');
 | 
					const clipperRoute = require('./api/clipper');
 | 
				
			||||||
const similarNotesRoute = require('./api/similar_notes.js');
 | 
					const similarNotesRoute = require('./api/similar_notes.js');
 | 
				
			||||||
const keysRoute = require('./api/keys.js');
 | 
					const keysRoute = require('./api/keys.js');
 | 
				
			||||||
const backendLogRoute = require('./api/backend_log');
 | 
					const backendLogRoute = require('./api/backend_log');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user