diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-01-05 12:01:42 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-01-05 12:01:42 +0000 |
| commit | 1f5d5668b7558ec4d0a77129041cba3ba6d72cb7 (patch) | |
| tree | 547276fbc89d5337c2f32ff6bcb37abe05f5c5dc /packages/trpc/routers | |
| parent | ce16eda75f4d93646e485b7115398e81e7c88acc (diff) | |
| download | karakeep-1f5d5668b7558ec4d0a77129041cba3ba6d72cb7.tar.zst | |
feat: Expose the search functionality in the REST API
Diffstat (limited to 'packages/trpc/routers')
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index f3884053..15e4cb7c 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -45,6 +45,8 @@ import { zGetBookmarksResponseSchema, zManipulatedTagSchema, zNewBookmarkRequestSchema, + zSearchBookmarksCursor, + zSearchBookmarksRequestSchema, zUpdateBookmarksRequestSchema, } from "@hoarder/shared/types/bookmarks"; @@ -521,29 +523,17 @@ export const bookmarksAppRouter = router({ return await getBookmark(ctx, input.bookmarkId); }), searchBookmarks: authedProcedure - .input( - z.object({ - text: z.string(), - cursor: z - .object({ - offset: z.number(), - limit: z.number(), - }) - .nullish(), - }), - ) + .input(zSearchBookmarksRequestSchema) .output( z.object({ bookmarks: z.array(zBookmarkSchema), - nextCursor: z - .object({ - offset: z.number(), - limit: z.number(), - }) - .nullable(), + nextCursor: zSearchBookmarksCursor.nullable(), }), ) .query(async ({ input, ctx }) => { + if (!input.limit) { + input.limit = DEFAULT_NUM_BOOKMARKS_PER_PAGE; + } const client = await getSearchIdxClient(); if (!client) { throw new TRPCError({ @@ -571,10 +561,10 @@ export const bookmarksAppRouter = router({ showRankingScore: true, attributesToRetrieve: ["id"], sort: ["createdAt:desc"], + limit: input.limit, ...(input.cursor ? { offset: input.cursor.offset, - limit: input.cursor.limit, } : {}), }); @@ -614,8 +604,8 @@ export const bookmarksAppRouter = router({ resp.hits.length + resp.offset >= resp.estimatedTotalHits ? null : { + ver: 1 as const, offset: resp.hits.length + resp.offset, - limit: resp.limit, }, }; }), |
