Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(core): integrate similar_notes route
Elian Doran3210dbb6d8c8
diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.tsindex e95e523f95..429cac69af 100644--- a/apps/server/src/routes/routes.ts+++ b/apps/server/src/routes/routes.ts@@ -36,7 +36,6 @@ import recoveryCodes from './api/recovery_codes.js';import scriptRoute from "./api/script.js";import senderRoute from "./api/sender.js";import setupApiRoute from "./api/setup.js";-import similarNotesRoute from "./api/similar_notes.js";import systemInfoRoute from "./api/system_info.js";import totp from './api/totp.js';// API routes@@ -212,7 +211,6 @@ function register(app: express.Application) {asyncRoute(PST, "/api/sender/image", [auth.checkEtapiToken, uploadMiddlewareWithErrorHandling], senderRoute.uploadImage, apiResultHandler);asyncRoute(PST, "/api/sender/note", [auth.checkEtapiToken], senderRoute.saveNote, apiResultHandler);- asyncApiRoute(GET, "/api/similar-notes/:noteId", similarNotesRoute.getSimilarNotes);asyncApiRoute(GET, "/api/backend-log", backendLogRoute.getBackendLog);route(GET, "/api/fonts", [auth.checkApiAuthOrElectron], fontsRoute.getFontCss);apiRoute(PST, "/api/other/render-markdown", otherRoute.renderMarkdown);diff --git a/apps/server/src/routes/api/similar_notes.ts b/packages/trilium-core/src/routes/api/similar_notes.tssimilarity index 79%rename from apps/server/src/routes/api/similar_notes.tsrename to packages/trilium-core/src/routes/api/similar_notes.tsindex 95306da71d..62bf3e985a 100644--- a/apps/server/src/routes/api/similar_notes.ts+++ b/packages/trilium-core/src/routes/api/similar_notes.ts@@ -1,13 +1,12 @@import { SimilarNoteResponse } from "@triliumnext/commons";-import { similarity } from "@triliumnext/core";import type { Request } from "express";import becca from "../../becca/becca.js";+import similarity from "../../becca/similarity.js";async function getSimilarNotes(req: Request<{ noteId: string }>) {const noteId = req.params.noteId;-- const _note = becca.getNoteOrThrow(noteId);+ becca.getNoteOrThrow(noteId);return (await similarity.findSimilarNotes(noteId) satisfies SimilarNoteResponse);}diff --git a/packages/trilium-core/src/routes/index.ts b/packages/trilium-core/src/routes/index.tsindex 7bb9bfcda7..2a30ca0574 100644--- a/packages/trilium-core/src/routes/index.ts+++ b/packages/trilium-core/src/routes/index.ts@@ -21,6 +21,7 @@ import searchRoute from "./api/search";import specialNotesRoute from "./api/special_notes";import syncApiRoute from "./api/sync";import autocompleteApiRoute from "./api/autocomplete";+import similarNotesRoute from "./api/similar_notes";// TODO: Deduplicate with routes.tsconst GET = "get",@@ -165,6 +166,7 @@ export function buildSharedApiRoutes({ route, apiRoute, asyncApiRoute, checkApiAapiRoute(GET, "/api/app-info", appInfoRoute.getAppInfo);apiRoute(GET, "/api/other/icon-usage", otherRoute.getIconUsage);+ asyncApiRoute(GET, "/api/similar-notes/:noteId", similarNotesRoute.getSimilarNotes);apiRoute(PST, "/api/relation-map", relationMapApiRoute.getRelationMap);apiRoute(GET, "/api/recent-changes/:ancestorNoteId", recentChangesApiRoute.getRecentChanges);}