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
fix(search): preserve route compatibility
Amp1e37f2bf382b
diff --git a/apps/server/internal.openapi.yaml b/apps/server/internal.openapi.yamlindex 63f020dcce..9d2105b605 100644--- a/apps/server/internal.openapi.yaml+++ b/apps/server/internal.openapi.yaml@@ -1922,6 +1922,7 @@ paths:required: trueschema:type: string+ minLength: 1responses:'200':description: Search results@@ -1931,6 +1932,8 @@ paths:type: arrayitems:$ref: '#/components/schemas/SearchResult'+ '400':+ description: Missing or empty search string/api/quick-search:get:@@ -1943,6 +1946,7 @@ paths:required: trueschema:type: string+ minLength: 1responses:'200':description: Quick search results@@ -1952,6 +1956,8 @@ paths:type: arrayitems:$ref: '#/components/schemas/SearchResult'+ '400':+ description: Missing or empty search string/api/search-note/{noteId}:get:diff --git a/packages/trilium-core/src/routes/api/search.spec.ts b/packages/trilium-core/src/routes/api/search.spec.tsindex 179570e953..9e645d67e7 100644--- a/packages/trilium-core/src/routes/api/search.spec.ts+++ b/packages/trilium-core/src/routes/api/search.spec.ts@@ -162,6 +162,18 @@ describe("Search API (core)", () => {}});+ it("keeps path parameters compatible with existing clients", async () => {+ const full = await api.get<string[]>(`/api/search/${UNIQUE_TOKEN}`);+ expect(full.status).toBe(200);+ expect(full.body).toContain(createdNoteId);++ const quick = await api.get<{ searchResultNoteIds: string[] }>(+ `/api/quick-search/${UNIQUE_TOKEN}`+ );+ expect(quick.status).toBe(200);+ expect(quick.body.searchResultNoteIds).toContain(createdNoteId);+ });+it("lists template note ids including a freshly-labelled template", async () => {const { noteId } = await createTextNote(api, { title: "A template note" });await api.post(`/api/notes/${noteId}/attributes`, {diff --git a/packages/trilium-core/src/routes/api/search.ts b/packages/trilium-core/src/routes/api/search.tsindex 20804a674c..f1231e2518 100644--- a/packages/trilium-core/src/routes/api/search.ts+++ b/packages/trilium-core/src/routes/api/search.ts@@ -110,7 +110,7 @@ function getSearchResultDetails(req: Request<{ noteId: string }>): SearchResultD};}-function quickSearch(req: Request) {+function quickSearch(req: Request<{ searchString?: string }>) {const searchString = getSearchString(req);const searchContext = new SearchContext({@@ -139,7 +139,7 @@ function quickSearch(req: Request) {}function search(- req: Request<unknown, unknown, unknown,+ req: Request<{ searchString?: string }, unknown, unknown,{ ancestorNoteId?: string, includeTokens?: string }>): string[] | SearchWithTokensResponse {const searchString = getSearchString(req);@@ -169,12 +169,14 @@ function search(};}-function getSearchString(req: Request): string {- if (typeof req.query.searchString !== "string" || req.query.searchString.length === 0) {+function getSearchString(req: Request<{ searchString?: string }>): string {+ const searchString = req.query.searchString ?? req.params.searchString;++ if (typeof searchString !== "string" || searchString.length === 0) {throw new ValidationError("Search string must be a string.");}- return req.query.searchString;+ return searchString;}function getRelatedNotes(req: Request) {diff --git a/packages/trilium-core/src/routes/index.ts b/packages/trilium-core/src/routes/index.tsindex 4ae7ec5eb9..e04cf2b52e 100644--- a/packages/trilium-core/src/routes/index.ts+++ b/packages/trilium-core/src/routes/index.ts@@ -236,11 +236,13 @@ export function buildSharedApiRoutes({ route, asyncRoute, asyncRouteWithoutTrans//#endregionapiRoute(GET, "/api/quick-search", searchRoute.quickSearch);+ apiRoute(GET, "/api/quick-search/:searchString", searchRoute.quickSearch);apiRoute(GET, "/api/search-note/:noteId", searchRoute.searchFromNote);apiRoute(PST, "/api/search-note/:noteId/result-details", searchRoute.getSearchResultDetails);apiRoute(PST, "/api/search-and-execute-note/:noteId", searchRoute.searchAndExecute);apiRoute(PST, "/api/search-related", searchRoute.getRelatedNotes);apiRoute(GET, "/api/search", searchRoute.search);+ apiRoute(GET, "/api/search/:searchString", searchRoute.search);apiRoute(GET, "/api/search-templates", searchRoute.searchTemplates);// Streaming a chat is not here — it has no single form every runtime can serve.