Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/main' into feat/share-search-snippets

Elian Dorancef67f8c0a79
diff --cc apps/server/src/share/routes.ts
index be08f7530b,e3446c7d6b..07334811c8
--- a/apps/server/src/share/routes.ts
+++ b/apps/server/src/share/routes.ts
@@@ -322,39 -435,24 +435,44 @@@ function register(router: Router)
const searchContext = new SearchContext({ ancestorNoteId });
const searchResults = searchService.findResultsWithQuery(search, searchContext);
-
- // Extract content snippets so the share viewer can show what matched.
- // Snippet extraction reads each note's content and runs token highlighting, so we
- // cap it to the first SNIPPET_LIMIT results (the share popout only renders 5).
- // Results beyond the cap are still returned, just without a snippet.
- const filteredResults = searchResults
++ const authorizedResults = searchResults
+ // Apply the same per-note authorization as the direct content routes:
+ // keep only results the caller may access and that are visible in the tree.
+ .filter((sr) => {
+ const fullNote = shaca.notes[sr.noteId];
+
+ return fullNote
+ && hasCredentialAccess(fullNote, req)
+ && isVisibleInShareTree(ancestorNoteId, sr.notePathArray);
- })
- .map((sr) => {
- const fullNote = shaca.notes[sr.noteId];
- const startIndex = sr.notePathArray.indexOf(ancestorNoteId);
- const localPathArray = sr.notePathArray.slice(startIndex + 1).filter((id) => shaca.notes[id]);
- const pathTitle = localPathArray.map((id) => shaca.notes[id].title).join(" / ");
- return { id: fullNote.shareId, title: fullNote.title, score: sr.score, path: pathTitle };
+ });
+
++ // Extract content snippets so the share viewer can show what matched. This runs only on
++ // results that passed the authorization filter above, so restricted content is never read.
++ // Snippet extraction reads each note's content and runs token highlighting, so we cap it
++ // to the first SNIPPET_LIMIT results (the share popout only renders 5). Results beyond
++ // the cap are still returned, just without a snippet.
++ // buildSearchResultDetails is the same builder the in-app quick search uses; it sets
++ // contentSnippet / highlightedContentSnippet (HTML-escaped, matched tokens wrapped in
++ // <b>...</b>) on each passed result.
+ const SNIPPET_LIMIT = 20;
- const snippetTargets = searchResults.slice(0, SNIPPET_LIMIT);
- const { highlightedTokens } = searchContext;
- for (const result of snippetTargets) {
- result.contentSnippet = searchService.extractContentSnippet(
- result.noteId, highlightedTokens
- );
- }
- // highlightSearchResults wraps matched tokens in <b>...</b> on highlightedContentSnippet.
- // We pass ignoreInternalAttributes=true to match the share UX (no internal attrs).
- searchService.highlightSearchResults(snippetTargets, highlightedTokens, true);
++ searchService.buildSearchResultDetails(authorizedResults.slice(0, SNIPPET_LIMIT), searchContext);
+
- const filteredResults = searchResults.map((sr) => {
++ const filteredResults = authorizedResults.map((sr) => {
+ const fullNote = shaca.notes[sr.noteId];
+ const startIndex = sr.notePathArray.indexOf(ancestorNoteId);
+ const localPathArray = sr.notePathArray.slice(startIndex + 1).filter((id) => shaca.notes[id]);
+ const pathTitle = localPathArray.map((id) => shaca.notes[id].title).join(" / ");
+ return {
+ id: fullNote.shareId,
+ title: fullNote.title,
+ score: sr.score,
+ path: pathTitle,
+ // Plain-text fallback and the <b>-highlighted variant from the search service.
+ snippet: sr.contentSnippet,
+ highlightedSnippet: sr.highlightedContentSnippet
+ };
+ });
+
res.json({ results: filteredResults });
});
}
diff --cc packages/share-theme/package.json
index 42297dcbb2,72639bde1f..84afba3ba2
--- a/packages/share-theme/package.json
+++ b/packages/share-theme/package.json
@@@ -31,13 -32,10 +32,11 @@@
"devDependencies": {
"@digitak/esrun": "3.2.26",
"@triliumnext/ckeditor5": "workspace:*",
- "@typescript-eslint/eslint-plugin": "8.59.4",
- "@typescript-eslint/parser": "8.59.4",
"dotenv": "17.4.2",
- "esbuild": "0.28.0",
- "eslint": "10.4.0",
- "highlight.js": "11.11.1",
+ "esbuild": "0.28.2",
+ "highlight.js": "11.12.0",
+ "sass": "1.103.1",
- "typescript": "6.0.3"
+ "typescript": "6.0.3",
- "vitest": "4.1.7"
++ "vitest": "4.1.11"
}
}
diff --cc pnpm-lock.yaml
index 48770e2fb3,0218e88f65..426ba355f5
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@@ -1625,9 -1354,6 +1354,9 @@@ importers
typescript:
specifier: 6.0.3
version: 6.0.3
+ vitest:
- specifier: 4.1.7
++ specifier: 4.1.11
packages/splitjs:
devDependencies: