add ability to set delete_video_after_link_expires
This commit is contained in:
parent
62555101b2
commit
a52dfcc7fb
3 changed files with 79 additions and 26 deletions
|
|
@ -16,17 +16,17 @@ datasource db {
|
|||
}
|
||||
|
||||
model Video {
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
title String
|
||||
video_url String
|
||||
userId String
|
||||
sharing Boolean @default(false)
|
||||
deleteAfterExpiry Boolean @default(false)
|
||||
shareExpiryAt DateTime?
|
||||
linkShareSeo Boolean @default(false)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
title String
|
||||
video_url String
|
||||
userId String
|
||||
sharing Boolean @default(false)
|
||||
delete_after_link_expires Boolean @default(false)
|
||||
shareExpiryAt DateTime?
|
||||
linkShareSeo Boolean @default(false)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export function ShareModal({ video }: Props) {
|
|||
}
|
||||
return { previousValue };
|
||||
},
|
||||
onError: async (err, { videoId }, context) => {
|
||||
onError: (err, { videoId }, context) => {
|
||||
if (context?.previousValue) {
|
||||
utils.video.get.setData({ videoId }, context.previousValue);
|
||||
}
|
||||
|
|
@ -28,6 +28,27 @@ export function ShareModal({ video }: Props) {
|
|||
},
|
||||
});
|
||||
|
||||
const setDeleteAfterLinkExpiresMutation =
|
||||
api.video.setDeleteAfterLinkExpires.useMutation({
|
||||
onMutate: async ({ videoId, delete_after_link_expires }) => {
|
||||
await utils.video.get.cancel();
|
||||
const previousValue = utils.video.get.getData({ videoId });
|
||||
if (previousValue) {
|
||||
utils.video.get.setData(
|
||||
{ videoId },
|
||||
{ ...previousValue, delete_after_link_expires }
|
||||
);
|
||||
}
|
||||
return { previousValue };
|
||||
},
|
||||
onError: (err, { videoId }, context) => {
|
||||
if (context?.previousValue) {
|
||||
utils.video.get.setData({ videoId }, context.previousValue);
|
||||
}
|
||||
console.error(err.message);
|
||||
},
|
||||
});
|
||||
|
||||
const [linkCopied, setLinkCopied] = useState<boolean>(false);
|
||||
|
||||
const handleCopy = () => {
|
||||
|
|
@ -104,25 +125,33 @@ export function ShareModal({ video }: Props) {
|
|||
{linkCopied ? "Copied!" : "Copy public link"}
|
||||
</button>
|
||||
<div className="w-full border border-solid border-[#e9ebf0] bg-[#fafbfc] px-[15px] py-3 text-xs">
|
||||
{/*<div className="flex h-6 items-center justify-between">*/}
|
||||
{/* <span>Expire link</span>*/}
|
||||
|
||||
{/* <button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">*/}
|
||||
{/* Never expire*/}
|
||||
{/* </button>*/}
|
||||
{/*</div>*/}
|
||||
{/*<div className="mt-3 flex h-6 items-center justify-between">*/}
|
||||
{/* <span>Delete video when expired</span>*/}
|
||||
{/* <ModernSwitch enabled={s} toggle={ss} />*/}
|
||||
{/*</div>*/}
|
||||
<div className="flex h-6 items-center justify-between">
|
||||
<span>Expire link</span>
|
||||
<button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">
|
||||
Never expire
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-3 flex h-6 items-center justify-between">
|
||||
<span>Share link with search engines</span>
|
||||
<span>Delete video after link expires</span>
|
||||
<ModernSwitch
|
||||
enabled={video.linkShareSeo}
|
||||
toggle={() => console.log("test")}
|
||||
enabled={video.delete_after_link_expires}
|
||||
toggle={() =>
|
||||
setDeleteAfterLinkExpiresMutation.mutate({
|
||||
videoId: video.id,
|
||||
delete_after_link_expires:
|
||||
!video.delete_after_link_expires,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{/*<div className="mt-3 flex h-6 items-center justify-between">*/}
|
||||
{/* <span>Share link with search engines</span>*/}
|
||||
{/* <ModernSwitch*/}
|
||||
{/* enabled={video.linkShareSeo}*/}
|
||||
{/* toggle={() => console.log("test")}*/}
|
||||
{/* />*/}
|
||||
{/*</div>*/}
|
||||
{/*<div className="mt-3 flex h-6 items-center justify-between">*/}
|
||||
{/* <span>Embed code</span>*/}
|
||||
{/* <button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">*/}
|
||||
{/* Copy code*/}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,30 @@ export const videoRouter = createTRPCRouter({
|
|||
throw new TRPCError({ code: "FORBIDDEN" });
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
updateVideo,
|
||||
};
|
||||
}),
|
||||
setDeleteAfterLinkExpires: protectedProcedure
|
||||
.input(
|
||||
z.object({ videoId: z.string(), delete_after_link_expires: z.boolean() })
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const updateVideo = await ctx.prisma.video.updateMany({
|
||||
where: {
|
||||
id: input.videoId,
|
||||
userId: ctx.session.user.id,
|
||||
},
|
||||
data: {
|
||||
delete_after_link_expires: input.delete_after_link_expires,
|
||||
},
|
||||
});
|
||||
|
||||
if (updateVideo.count === 0) {
|
||||
throw new TRPCError({ code: "FORBIDDEN" });
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
updateVideo,
|
||||
|
|
|
|||
Loading…
Reference in a new issue