From 3210dbb6d8c8ee7d192b19b4d435e705d7863c7b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 23 Mar 2026 16:29:59 +0200 Subject: [PATCH] feat(core): integrate similar_notes route --- apps/server/src/routes/routes.ts | 2 -- .../trilium-core}/src/routes/api/similar_notes.ts | 5 ++--- packages/trilium-core/src/routes/index.ts | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) rename {apps/server => packages/trilium-core}/src/routes/api/similar_notes.ts (79%) diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.ts index 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.ts similarity index 79% rename from apps/server/src/routes/api/similar_notes.ts rename to packages/trilium-core/src/routes/api/similar_notes.ts index 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.ts index 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.ts const GET = "get", @@ -165,6 +166,7 @@ export function buildSharedApiRoutes({ route, apiRoute, asyncApiRoute, checkApiA apiRoute(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); }