add viewing video list event

This commit is contained in:
MarconLP 2023-04-23 13:17:52 +02:00
parent ba7766f2f6
commit ea5166c416
No known key found for this signature in database
GPG key ID: A08A9C8B623F5EA5

View file

@ -15,29 +15,40 @@ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { TRPCError } from "@trpc/server";
export const videoRouter = createTRPCRouter({
getAll: protectedProcedure.query(async ({ ctx }) => {
const videos = await ctx.prisma.video.findMany({
where: {
userId: ctx.session.user.id,
},
});
getAll: protectedProcedure.query(
async ({ ctx: { prisma, session, s3, posthog } }) => {
const videos = await prisma.video.findMany({
where: {
userId: session.user.id,
},
});
const videosWithThumbnailUrl = await Promise.all(
videos.map(async (video) => {
const thumbnailUrl = await getSignedUrl(
ctx.s3,
new GetObjectCommand({
Bucket: env.AWS_BUCKET_NAME,
Key: video.userId + "/" + video.id + "-thumbnail",
})
);
posthog.capture({
distinctId: session.user.id,
event: "viewing video list",
properties: {
videoAmount: videos.length,
},
});
void posthog.shutdownAsync();
return { ...video, thumbnailUrl };
})
);
const videosWithThumbnailUrl = await Promise.all(
videos.map(async (video) => {
const thumbnailUrl = await getSignedUrl(
s3,
new GetObjectCommand({
Bucket: env.AWS_BUCKET_NAME,
Key: video.userId + "/" + video.id + "-thumbnail",
})
);
return videosWithThumbnailUrl;
}),
return { ...video, thumbnailUrl };
})
);
return videosWithThumbnailUrl;
}
),
get: publicProcedure
.input(z.object({ videoId: z.string() }))
.query(async ({ ctx, input }) => {