add video upload events
This commit is contained in:
parent
ea5166c416
commit
9eb531a3e8
1 changed files with 27 additions and 8 deletions
|
|
@ -95,20 +95,29 @@ export const videoRouter = createTRPCRouter({
|
||||||
}),
|
}),
|
||||||
getUploadUrl: protectedProcedure
|
getUploadUrl: protectedProcedure
|
||||||
.input(z.object({ key: z.string() }))
|
.input(z.object({ key: z.string() }))
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx: { prisma, session, s3, posthog }, input }) => {
|
||||||
const { key } = input;
|
const { key } = input;
|
||||||
const { s3 } = ctx;
|
|
||||||
|
|
||||||
const videos = await ctx.prisma.video.findMany({
|
const videos = await prisma.video.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: ctx.session.user.id,
|
userId: session.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
videos.length >= 10 &&
|
videos.length >= 10 &&
|
||||||
ctx.session.user.stripeSubscriptionStatus !== "active"
|
session.user.stripeSubscriptionStatus !== "active"
|
||||||
) {
|
) {
|
||||||
|
posthog.capture({
|
||||||
|
distinctId: session.user.id,
|
||||||
|
event: "hit video upload limit",
|
||||||
|
properties: {
|
||||||
|
videoAmount: videos.length,
|
||||||
|
stripeSubscriptionStatus: session.user.stripeSubscriptionStatus,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
void posthog.shutdownAsync();
|
||||||
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "FORBIDDEN",
|
code: "FORBIDDEN",
|
||||||
message:
|
message:
|
||||||
|
|
@ -116,9 +125,19 @@ export const videoRouter = createTRPCRouter({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const video = await ctx.prisma.video.create({
|
posthog.capture({
|
||||||
|
distinctId: session.user.id,
|
||||||
|
event: "uploading video",
|
||||||
|
properties: {
|
||||||
|
videoAmount: videos.length,
|
||||||
|
stripeSubscriptionStatus: session.user.stripeSubscriptionStatus,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
void posthog.shutdownAsync();
|
||||||
|
|
||||||
|
const video = await prisma.video.create({
|
||||||
data: {
|
data: {
|
||||||
userId: ctx.session.user.id,
|
userId: session.user.id,
|
||||||
title: key,
|
title: key,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -127,7 +146,7 @@ export const videoRouter = createTRPCRouter({
|
||||||
s3,
|
s3,
|
||||||
new PutObjectCommand({
|
new PutObjectCommand({
|
||||||
Bucket: env.AWS_BUCKET_NAME,
|
Bucket: env.AWS_BUCKET_NAME,
|
||||||
Key: ctx.session.user.id + "/" + video.id,
|
Key: session.user.id + "/" + video.id,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue