From bc65a73872cf0707d2433c289d1f04423325ed95 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 7 Jun 2025 16:46:36 +0000 Subject: fix: Use a new public list metadata endpoint for metadata generation --- packages/trpc/models/lists.ts | 44 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'packages/trpc/models') 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; - 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; + 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()), -- cgit v1.2.3-70-g09d2