diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-01-13 00:00:30 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-01-13 00:00:30 +0000 |
| commit | bbbf33536c6c1a73fdfe76c42ff19cd08aabcc6f (patch) | |
| tree | 7a3360c682da1908e60e5747063ca68719e026fe /packages/trpc/lib | |
| parent | 38d403bcc26244e778a6e7a2f75ee39a9ec7ed27 (diff) | |
| download | karakeep-bbbf33536c6c1a73fdfe76c42ff19cd08aabcc6f.tar.zst | |
fix: Fix url matcher not matching sourceUrl. Fixes #874
Diffstat (limited to 'packages/trpc/lib')
| -rw-r--r-- | packages/trpc/lib/__tests__/search.test.ts | 3 | ||||
| -rw-r--r-- | packages/trpc/lib/search.ts | 27 |
2 files changed, 25 insertions, 5 deletions
diff --git a/packages/trpc/lib/__tests__/search.test.ts b/packages/trpc/lib/__tests__/search.test.ts index 8a6f1949..7f573b4f 100644 --- a/packages/trpc/lib/__tests__/search.test.ts +++ b/packages/trpc/lib/__tests__/search.test.ts @@ -111,6 +111,7 @@ beforeEach(async () => { assetType: "image", fileName: "test.png", assetId: "asset-id", + sourceUrl: "https://example.com/image.png", }, ]); @@ -236,7 +237,7 @@ describe("getBookmarkIdsFromMatcher", () => { inverse: false, }; const result = await getBookmarkIdsFromMatcher(mockCtx, matcher); - expect(result).toEqual(["b1", "b4"]); + expect(result).toEqual(["b1", "b4", "b6"]); }); it("should handle url matcher with inverse=true", async () => { diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts index eac323df..de76748b 100644 --- a/packages/trpc/lib/search.ts +++ b/packages/trpc/lib/search.ts @@ -4,6 +4,7 @@ import { exists, gt, gte, + isNotNull, like, lt, lte, @@ -13,6 +14,7 @@ import { } from "drizzle-orm"; import { + bookmarkAssets, bookmarkLinks, bookmarkLists, bookmarks, @@ -197,6 +199,20 @@ async function getIds( eq(bookmarks.userId, userId), comp(bookmarkLinks.url, `%${matcher.url}%`), ), + ) + .union( + db + .select({ id: bookmarkAssets.id }) + .from(bookmarkAssets) + .leftJoin(bookmarks, eq(bookmarks.id, bookmarkAssets.id)) + .where( + and( + eq(bookmarks.userId, userId), + // When a user is asking for a link, the inverse matcher should match only assets with URLs. + isNotNull(bookmarkAssets.sourceUrl), + comp(bookmarkAssets.sourceUrl, `%${matcher.url}%`), + ), + ), ); } case "favourited": { @@ -235,13 +251,16 @@ async function getIds( ); } case "type": { - const comp = matcher.inverse - ? ne(bookmarks.type, matcher.typeName) - : eq(bookmarks.type, matcher.typeName); + const comp = matcher.inverse ? ne : eq; return db .select({ id: bookmarks.id }) .from(bookmarks) - .where(and(eq(bookmarks.userId, userId), comp)); + .where( + and( + eq(bookmarks.userId, userId), + comp(bookmarks.type, matcher.typeName), + ), + ); } case "and": { const vals = await Promise.all( |
