aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/models/lists.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-06-07 16:46:36 +0000
committerMohamed Bassem <me@mbassem.com>2025-06-07 16:46:36 +0000
commitbc65a73872cf0707d2433c289d1f04423325ed95 (patch)
tree95de3c17907e0ea79fbca1d058263b87b3bb4c6f /packages/trpc/models/lists.ts
parenta98f02369c5b2aea8831cbbff840fbd2ae395a7d (diff)
downloadkarakeep-bc65a73872cf0707d2433c289d1f04423325ed95.tar.zst
fix: Use a new public list metadata endpoint for metadata generation
Diffstat (limited to 'packages/trpc/models/lists.ts')
-rw-r--r--packages/trpc/models/lists.ts44
1 files changed, 38 insertions, 6 deletions
diff --git a/packages/trpc/models/lists.ts b/packages/trpc/models/lists.ts
index 2631ca7e..39d78ac1 100644
--- a/packages/trpc/models/lists.ts
+++ b/packages/trpc/models/lists.ts
@@ -63,15 +63,10 @@ export abstract class List implements PrivacyAware {
}
}
- static async getPublicListContents(
+ private static async getPublicList(
ctx: Context,
listId: string,
token: string | null,
- pagination: {
- limit: number;
- order: Exclude<ZSortOrder, "relevance">;
- cursor: ZCursor | null | undefined;
- },
) {
const listdb = await ctx.db.query.bookmarkLists.findFirst({
where: and(
@@ -81,6 +76,13 @@ export abstract class List implements PrivacyAware {
token !== null ? eq(bookmarkLists.rssToken, token) : undefined,
),
),
+ with: {
+ user: {
+ columns: {
+ name: true,
+ },
+ },
+ },
});
if (!listdb) {
throw new TRPCError({
@@ -88,6 +90,35 @@ export abstract class List implements PrivacyAware {
message: "List not found",
});
}
+ return listdb;
+ }
+
+ static async getPublicListMetadata(
+ ctx: Context,
+ listId: string,
+ token: string | null,
+ ) {
+ const listdb = await this.getPublicList(ctx, listId, token);
+ return {
+ userId: listdb.userId,
+ name: listdb.name,
+ description: listdb.description,
+ icon: listdb.icon,
+ ownerName: listdb.user.name,
+ };
+ }
+
+ static async getPublicListContents(
+ ctx: Context,
+ listId: string,
+ token: string | null,
+ pagination: {
+ limit: number;
+ order: Exclude<ZSortOrder, "relevance">;
+ cursor: ZCursor | null | undefined;
+ },
+ ) {
+ const listdb = await this.getPublicList(ctx, listId, token);
// The token here acts as an authed context, so we can create
// an impersonating context for the list owner as long as
@@ -109,6 +140,7 @@ export abstract class List implements PrivacyAware {
icon: list.list.icon,
name: list.list.name,
description: list.list.description,
+ ownerName: listdb.user.name,
numItems: bookmarkIds.length,
},
bookmarks: bookmarks.bookmarks.map((b) => b.asPublicBookmark()),