chore(client-standalone): integrate note map backlink count

This commit is contained in:
Elian Doran 2026-01-07 16:36:49 +02:00
parent 91db73703b
commit 13f25e9fed
No known key found for this signature in database
4 changed files with 32 additions and 12 deletions

View File

@ -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
};

View File

@ -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);

View File

@ -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
}

View File

@ -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);
}