From 13f25e9fed6ec6d7b66154abe33106c189ee179b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 7 Jan 2026 16:36:49 +0200 Subject: [PATCH] chore(client-standalone): integrate note map backlink count --- apps/server/src/routes/api/note_map.ts | 12 +------- apps/server/src/routes/routes.ts | 1 - .../trilium-core/src/routes/api/note_map.ts | 28 +++++++++++++++++++ packages/trilium-core/src/routes/index.ts | 3 ++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 packages/trilium-core/src/routes/api/note_map.ts diff --git a/apps/server/src/routes/api/note_map.ts b/apps/server/src/routes/api/note_map.ts index 473388af0..69d8f3bcf 100644 --- a/apps/server/src/routes/api/note_map.ts +++ b/apps/server/src/routes/api/note_map.ts @@ -341,6 +341,7 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) { return excerpts; } +// TODO: Deduplicate with core function getFilteredBacklinks(note: BNote): BAttribute[] { return ( note @@ -350,16 +351,6 @@ function getFilteredBacklinks(note: BNote): BAttribute[] { ); } -function getBacklinkCount(req: Request) { - const { noteId } = req.params; - - const note = becca.getNoteOrThrow(noteId); - - return { - count: getFilteredBacklinks(note).length - } satisfies BacklinkCountResponse; -} - function getBacklinks(req: Request): BacklinksResponse { const { noteId } = req.params; const note = becca.getNoteOrThrow(noteId); @@ -389,6 +380,5 @@ function getBacklinks(req: Request): BacklinksResponse { export default { getLinkMap, getTreeMap, - getBacklinkCount, getBacklinks }; diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.ts index c9efb42f8..57f1e61bb 100644 --- a/apps/server/src/routes/routes.ts +++ b/apps/server/src/routes/routes.ts @@ -312,7 +312,6 @@ function register(app: express.Application) { apiRoute(PST, "/api/note-map/:noteId/tree", noteMapRoute.getTreeMap); apiRoute(PST, "/api/note-map/:noteId/link", noteMapRoute.getLinkMap); - apiRoute(GET, "/api/note-map/:noteId/backlink-count", noteMapRoute.getBacklinkCount); apiRoute(GET, "/api/note-map/:noteId/backlinks", noteMapRoute.getBacklinks); shareRoutes.register(router); diff --git a/packages/trilium-core/src/routes/api/note_map.ts b/packages/trilium-core/src/routes/api/note_map.ts new file mode 100644 index 000000000..d42e98958 --- /dev/null +++ b/packages/trilium-core/src/routes/api/note_map.ts @@ -0,0 +1,28 @@ +import type { Request } from "express"; +import BAttribute from "../../becca/entities/battribute"; +import BNote from "../../becca/entities/bnote"; +import becca from "../../becca/becca"; +import type { BacklinkCountResponse } from "@triliumnext/commons"; + +function getFilteredBacklinks(note: BNote): BAttribute[] { + return ( + note + .getTargetRelations() + // search notes have "ancestor" relations which are not interesting + .filter((relation) => !!relation.getNote() && relation.getNote().type !== "search") + ); +} + +function getBacklinkCount(req: Request) { + const { noteId } = req.params; + + const note = becca.getNoteOrThrow(noteId); + + return { + count: getFilteredBacklinks(note).length + } satisfies BacklinkCountResponse; +} + +export default { + getBacklinkCount +} diff --git a/packages/trilium-core/src/routes/index.ts b/packages/trilium-core/src/routes/index.ts index 0d0b11cff..bff4a3eaf 100644 --- a/packages/trilium-core/src/routes/index.ts +++ b/packages/trilium-core/src/routes/index.ts @@ -3,6 +3,7 @@ import treeApiRoute from "./api/tree"; import keysApiRoute from "./api/keys"; import notesApiRoute from "./api/notes"; import attachmentsApiRoute from "./api/attachments"; +import noteMapRoute from "./api/note_map"; import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity"; // TODO: Deduplicate with routes.ts @@ -50,6 +51,8 @@ export function buildSharedApiRoutes(apiRoute: any) { apiRoute(PUT, "/api/attachments/:attachmentId/rename", attachmentsApiRoute.renameAttachment); apiRoute(GET, "/api/attachments/:attachmentId/blob", attachmentsApiRoute.getAttachmentBlob); + apiRoute(GET, "/api/note-map/:noteId/backlink-count", noteMapRoute.getBacklinkCount); + apiRoute(GET, "/api/keyboard-actions", keysApiRoute.getKeyboardActions); apiRoute(GET, "/api/keyboard-shortcuts-for-notes", keysApiRoute.getShortcutsForNotes); }