mirror of
https://github.com/zadam/trilium.git
synced 2026-01-08 16:32:13 +01:00
chore(core): integrate notes route
This commit is contained in:
@@ -37,7 +37,6 @@ import llmRoute from "./api/llm.js";
|
||||
import loginApiRoute from "./api/login.js";
|
||||
import metricsRoute from "./api/metrics.js";
|
||||
import noteMapRoute from "./api/note_map.js";
|
||||
import notesApiRoute from "./api/notes.js";
|
||||
import ollamaRoute from "./api/ollama.js";
|
||||
import openaiRoute from "./api/openai.js";
|
||||
import otherRoute from "./api/other.js";
|
||||
@@ -105,19 +104,6 @@ function register(app: express.Application) {
|
||||
|
||||
routes.buildSharedApiRoutes(apiRoute);
|
||||
|
||||
apiRoute(GET, "/api/notes/:noteId", notesApiRoute.getNote);
|
||||
apiRoute(GET, "/api/notes/:noteId/blob", notesApiRoute.getNoteBlob);
|
||||
apiRoute(GET, "/api/notes/:noteId/metadata", notesApiRoute.getNoteMetadata);
|
||||
apiRoute(PUT, "/api/notes/:noteId/data", notesApiRoute.updateNoteData);
|
||||
apiRoute(DEL, "/api/notes/:noteId", notesApiRoute.deleteNote);
|
||||
apiRoute(PUT, "/api/notes/:noteId/undelete", notesApiRoute.undeleteNote);
|
||||
apiRoute(PST, "/api/notes/:noteId/revision", notesApiRoute.forceSaveRevision);
|
||||
apiRoute(PST, "/api/notes/:parentNoteId/children", notesApiRoute.createNote);
|
||||
apiRoute(PUT, "/api/notes/:noteId/sort-children", notesApiRoute.sortChildNotes);
|
||||
apiRoute(PUT, "/api/notes/:noteId/protect/:isProtected", notesApiRoute.protectNote);
|
||||
apiRoute(PUT, "/api/notes/:noteId/type", notesApiRoute.setNoteTypeMime);
|
||||
apiRoute(PUT, "/api/notes/:noteId/title", notesApiRoute.changeTitle);
|
||||
apiRoute(PST, "/api/notes/:noteId/duplicate/:parentNoteId", notesApiRoute.duplicateSubtree);
|
||||
apiRoute(PUT, "/api/notes/:noteId/clone-to-branch/:parentBranchId", cloningApiRoute.cloneNoteToBranch);
|
||||
apiRoute(PUT, "/api/notes/:noteId/toggle-in-parent/:parentNoteId/:present", cloningApiRoute.toggleNoteInParent);
|
||||
apiRoute(PUT, "/api/notes/:noteId/clone-to-note/:parentNoteId", cloningApiRoute.cloneNoteToParentNote);
|
||||
@@ -139,7 +125,6 @@ function register(app: express.Application) {
|
||||
route(GET, "/api/notes/download/:noteId", [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
|
||||
apiRoute(PST, "/api/notes/:noteId/save-to-tmp-dir", filesRoute.saveNoteToTmpDir);
|
||||
apiRoute(PST, "/api/notes/:noteId/upload-modified-file", filesRoute.uploadModifiedFileToNote);
|
||||
apiRoute(PST, "/api/notes/:noteId/convert-to-attachment", notesApiRoute.convertNoteToAttachment);
|
||||
|
||||
apiRoute(PUT, "/api/branches/:branchId/move-to/:parentBranchId", branchesApiRoute.moveBranchToParent);
|
||||
apiRoute(PUT, "/api/branches/:branchId/move-before/:beforeBranchId", branchesApiRoute.moveBranchBeforeNote);
|
||||
@@ -322,13 +307,10 @@ function register(app: express.Application) {
|
||||
asyncRoute(PST, "/api/sender/note", [auth.checkEtapiToken], senderRoute.saveNote, apiResultHandler);
|
||||
|
||||
apiRoute(PST, "/api/relation-map", relationMapApiRoute.getRelationMap);
|
||||
apiRoute(PST, "/api/notes/erase-deleted-notes-now", notesApiRoute.eraseDeletedNotesNow);
|
||||
apiRoute(PST, "/api/notes/erase-unused-attachments-now", notesApiRoute.eraseUnusedAttachmentsNow);
|
||||
asyncApiRoute(GET, "/api/similar-notes/:noteId", similarNotesRoute.getSimilarNotes);
|
||||
asyncApiRoute(GET, "/api/backend-log", backendLogRoute.getBackendLog);
|
||||
apiRoute(GET, "/api/stats/note-size/:noteId", statsRoute.getNoteSize);
|
||||
apiRoute(GET, "/api/stats/subtree-size/:noteId", statsRoute.getSubtreeSize);
|
||||
apiRoute(PST, "/api/delete-notes-preview", notesApiRoute.getDeleteNotesPreview);
|
||||
route(GET, "/api/fonts", [auth.checkApiAuthOrElectron], fontsRoute.getFontCss);
|
||||
apiRoute(GET, "/api/other/icon-usage", otherRoute.getIconUsage);
|
||||
apiRoute(PST, "/api/other/render-markdown", otherRoute.renderMarkdown);
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import type { AttributeRow, CreateChildrenResponse, DeleteNotesPreview, MetadataResponse } from "@triliumnext/commons";
|
||||
import { blob as blobService, erase as eraseService, ValidationError } from "@triliumnext/core";
|
||||
import type { Request } from "express";
|
||||
|
||||
import blobService from "../../services/blob";
|
||||
import eraseService from "../../services/erase.js";
|
||||
import { ValidationError } from "../../errors.js";
|
||||
import becca from "../../becca/becca.js";
|
||||
import type BBranch from "../../becca/entities/bbranch.js";
|
||||
import log from "../../services/log.js";
|
||||
import { getLog } from "../../services/log.js";
|
||||
import noteService from "../../services/notes.js";
|
||||
import sql from "../../services/sql.js";
|
||||
import { getSql } from "../../services/sql/index";
|
||||
import TaskContext from "../../services/task_context.js";
|
||||
import treeService from "../../services/tree.js";
|
||||
import utils from "../../services/utils.js";
|
||||
import { randomString } from "../../services/utils/index";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -174,7 +176,7 @@ function deleteNote(req: Request) {
|
||||
const last = req.query.last === "true";
|
||||
|
||||
// note how deleteId is separate from taskId - single taskId produces separate deleteId for each "top level" deleted note
|
||||
const deleteId = utils.randomString(10);
|
||||
const deleteId = randomString(10);
|
||||
|
||||
const note = becca.getNoteOrThrow(noteId);
|
||||
|
||||
@@ -195,7 +197,7 @@ function deleteNote(req: Request) {
|
||||
}
|
||||
|
||||
function undeleteNote(req: Request) {
|
||||
const taskContext = TaskContext.getInstance(utils.randomString(10), "undeleteNotes", null);
|
||||
const taskContext = TaskContext.getInstance(randomString(10), "undeleteNotes", null);
|
||||
|
||||
noteService.undeleteNote(req.params.noteId, taskContext);
|
||||
|
||||
@@ -206,7 +208,7 @@ function sortChildNotes(req: Request) {
|
||||
const noteId = req.params.noteId;
|
||||
const { sortBy, sortDirection, foldersFirst, sortNatural, sortLocale } = req.body;
|
||||
|
||||
log.info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}, foldersFirst=${foldersFirst}, sortNatural=${sortNatural}, sortLocale=${sortLocale}`);
|
||||
getLog().info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}, foldersFirst=${foldersFirst}, sortNatural=${sortNatural}, sortLocale=${sortLocale}`);
|
||||
|
||||
const reverse = sortDirection === "desc";
|
||||
|
||||
@@ -219,7 +221,7 @@ function protectNote(req: Request) {
|
||||
const protect = !!parseInt(req.params.isProtected);
|
||||
const includingSubTree = !!parseInt(req.query?.subtree as string);
|
||||
|
||||
const taskContext = new TaskContext(utils.randomString(10), "protectNotes", { protect });
|
||||
const taskContext = new TaskContext(randomString(10), "protectNotes", { protect });
|
||||
|
||||
noteService.protectNoteRecursively(note, protect, includingSubTree, taskContext);
|
||||
|
||||
@@ -307,7 +309,7 @@ function getDeleteNotesPreview(req: Request) {
|
||||
const branch = becca.getBranch(branchId);
|
||||
|
||||
if (!branch) {
|
||||
log.error(`Branch ${branchId} was not found and delete preview can't be calculated for this note.`);
|
||||
getLog().error(`Branch ${branchId} was not found and delete preview can't be calculated for this note.`);
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -318,6 +320,7 @@ function getDeleteNotesPreview(req: Request) {
|
||||
let brokenRelations: AttributeRow[] = [];
|
||||
|
||||
if (noteIdsToBeDeleted.size > 0) {
|
||||
const sql = getSql();
|
||||
sql.fillParamList(noteIdsToBeDeleted);
|
||||
|
||||
// FIXME: No need to do this in database, can be done with becca data
|
||||
@@ -1,6 +1,7 @@
|
||||
import optionsApiRoute from "./api/options";
|
||||
import treeApiRoute from "./api/tree";
|
||||
import keysApiRoute from "./api/keys";
|
||||
import notesApiRoute from "./api/notes";
|
||||
|
||||
// TODO: Deduplicate with routes.ts
|
||||
const GET = "get",
|
||||
@@ -20,6 +21,24 @@ export function buildSharedApiRoutes(apiRoute: any) {
|
||||
apiRoute(GET, "/api/options/user-themes", optionsApiRoute.getUserThemes);
|
||||
apiRoute(GET, "/api/options/locales", optionsApiRoute.getSupportedLocales);
|
||||
|
||||
apiRoute(PST, "/api/notes/:noteId/convert-to-attachment", notesApiRoute.convertNoteToAttachment);
|
||||
apiRoute(GET, "/api/notes/:noteId", notesApiRoute.getNote);
|
||||
apiRoute(GET, "/api/notes/:noteId/blob", notesApiRoute.getNoteBlob);
|
||||
apiRoute(GET, "/api/notes/:noteId/metadata", notesApiRoute.getNoteMetadata);
|
||||
apiRoute(PUT, "/api/notes/:noteId/data", notesApiRoute.updateNoteData);
|
||||
apiRoute(DEL, "/api/notes/:noteId", notesApiRoute.deleteNote);
|
||||
apiRoute(PUT, "/api/notes/:noteId/undelete", notesApiRoute.undeleteNote);
|
||||
apiRoute(PST, "/api/notes/:noteId/revision", notesApiRoute.forceSaveRevision);
|
||||
apiRoute(PST, "/api/notes/:parentNoteId/children", notesApiRoute.createNote);
|
||||
apiRoute(PUT, "/api/notes/:noteId/sort-children", notesApiRoute.sortChildNotes);
|
||||
apiRoute(PUT, "/api/notes/:noteId/protect/:isProtected", notesApiRoute.protectNote);
|
||||
apiRoute(PUT, "/api/notes/:noteId/type", notesApiRoute.setNoteTypeMime);
|
||||
apiRoute(PUT, "/api/notes/:noteId/title", notesApiRoute.changeTitle);
|
||||
apiRoute(PST, "/api/notes/:noteId/duplicate/:parentNoteId", notesApiRoute.duplicateSubtree);
|
||||
apiRoute(PST, "/api/notes/erase-deleted-notes-now", notesApiRoute.eraseDeletedNotesNow);
|
||||
apiRoute(PST, "/api/notes/erase-unused-attachments-now", notesApiRoute.eraseUnusedAttachmentsNow);
|
||||
apiRoute(PST, "/api/delete-notes-preview", notesApiRoute.getDeleteNotesPreview);
|
||||
|
||||
apiRoute(GET, "/api/keyboard-actions", keysApiRoute.getKeyboardActions);
|
||||
apiRoute(GET, "/api/keyboard-shortcuts-for-notes", keysApiRoute.getShortcutsForNotes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user