diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-01-02 13:00:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-02 13:00:58 +0200 |
| commit | 5ecdc36b7d60aa66b49e01e9fec8ba61ad537376 (patch) | |
| tree | 57577822bb104b95900ba577a265fb4f8cf70b78 /packages/trpc/routers/bookmarks.ts | |
| parent | 5df0258b2cd884347eabfa866d7e7fbc7225cdb3 (diff) | |
| download | karakeep-5ecdc36b7d60aa66b49e01e9fec8ba61ad537376.tar.zst | |
feat: Add support for smart lists (#802)
* feat: Add support for smart lists
* i18n
* Fix update list endpoint
* Add a test for smart lists
* Add header to the query explainer
* Hide remove from lists in the smart context list
* Add proper validation to list form
---------
Co-authored-by: Deepak Kapoor <41769111+orthdron@users.noreply.github.com>
Diffstat (limited to 'packages/trpc/routers/bookmarks.ts')
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 3320b3b9..47ba623b 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -14,6 +14,7 @@ import { AssetTypes, bookmarkAssets, bookmarkLinks, + bookmarkLists, bookmarks, bookmarksInLists, bookmarkTags, @@ -33,6 +34,7 @@ import { triggerSearchReindex, } from "@hoarder/shared/queues"; import { getSearchIdxClient } from "@hoarder/shared/search"; +import { parseSearchQuery } from "@hoarder/shared/searchQueryParser"; import { BookmarkTypes, DEFAULT_NUM_BOOKMARKS_PER_PAGE, @@ -625,6 +627,34 @@ export const bookmarksAppRouter = router({ if (!input.limit) { input.limit = DEFAULT_NUM_BOOKMARKS_PER_PAGE; } + if (input.listId) { + const list = await ctx.db.query.bookmarkLists.findFirst({ + where: and( + eq(bookmarkLists.id, input.listId), + eq(bookmarkLists.userId, ctx.user.id), + ), + }); + if (!list) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "List not found", + }); + } + if (list.type === "smart") { + invariant(list.query); + const query = parseSearchQuery(list.query); + if (query.result !== "full") { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Found an invalid smart list query", + }); + } + if (query.matcher) { + input.ids = await getBookmarkIdsFromMatcher(ctx, query.matcher); + delete input.listId; + } + } + } const sq = ctx.db.$with("bookmarksSq").as( ctx.db |
