aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/bookmarks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc/routers/bookmarks.ts')
-rw-r--r--packages/trpc/routers/bookmarks.ts30
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