aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc')
-rw-r--r--packages/trpc/models/lists.ts44
-rw-r--r--packages/trpc/routers/publicBookmarks.ts24
2 files changed, 61 insertions, 7 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()),
diff --git a/packages/trpc/routers/publicBookmarks.ts b/packages/trpc/routers/publicBookmarks.ts
index 6b643354..be852b67 100644
--- a/packages/trpc/routers/publicBookmarks.ts
+++ b/packages/trpc/routers/publicBookmarks.ts
@@ -12,6 +12,28 @@ import { publicProcedure, router } from "../index";
import { List } from "../models/lists";
export const publicBookmarks = router({
+ getPublicListMetadata: publicProcedure
+ .input(
+ z.object({
+ listId: z.string(),
+ }),
+ )
+ .output(
+ zBookmarkListSchema
+ .pick({
+ name: true,
+ description: true,
+ icon: true,
+ })
+ .merge(z.object({ ownerName: z.string() })),
+ )
+ .query(async ({ input, ctx }) => {
+ return await List.getPublicListMetadata(
+ ctx,
+ input.listId,
+ /* token */ null,
+ );
+ }),
getPublicBookmarksInList: publicProcedure
.input(
z.object({
@@ -29,7 +51,7 @@ export const publicBookmarks = router({
description: true,
icon: true,
})
- .merge(z.object({ numItems: z.number() })),
+ .merge(z.object({ numItems: z.number(), ownerName: z.string() })),
bookmarks: z.array(zPublicBookmarkSchema),
nextCursor: zCursorV2.nullable(),
}),