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 {
|
model Video {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
title String
|
title String
|
||||||
video_url String
|
video_url String
|
||||||
userId String
|
userId String
|
||||||
sharing Boolean @default(false)
|
sharing Boolean @default(false)
|
||||||
deleteAfterExpiry Boolean @default(false)
|
delete_after_link_expires Boolean @default(false)
|
||||||
shareExpiryAt DateTime?
|
shareExpiryAt DateTime?
|
||||||
linkShareSeo Boolean @default(false)
|
linkShareSeo Boolean @default(false)
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export function ShareModal({ video }: Props) {
|
||||||
}
|
}
|
||||||
return { previousValue };
|
return { previousValue };
|
||||||
},
|
},
|
||||||
onError: async (err, { videoId }, context) => {
|
onError: (err, { videoId }, context) => {
|
||||||
if (context?.previousValue) {
|
if (context?.previousValue) {
|
||||||
utils.video.get.setData({ videoId }, 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 [linkCopied, setLinkCopied] = useState<boolean>(false);
|
||||||
|
|
||||||
const handleCopy = () => {
|
const handleCopy = () => {
|
||||||
|
|
@ -104,25 +125,33 @@ export function ShareModal({ video }: Props) {
|
||||||
{linkCopied ? "Copied!" : "Copy public link"}
|
{linkCopied ? "Copied!" : "Copy public link"}
|
||||||
</button>
|
</button>
|
||||||
<div className="w-full border border-solid border-[#e9ebf0] bg-[#fafbfc] px-[15px] py-3 text-xs">
|
<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">*/}
|
<div className="flex h-6 items-center justify-between">
|
||||||
{/* <span>Expire link</span>*/}
|
<span>Expire link</span>
|
||||||
|
<button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">
|
||||||
{/* <button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">*/}
|
Never expire
|
||||||
{/* Never expire*/}
|
</button>
|
||||||
{/* </button>*/}
|
</div>
|
||||||
{/*</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="mt-3 flex h-6 items-center justify-between">
|
<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
|
<ModernSwitch
|
||||||
enabled={video.linkShareSeo}
|
enabled={video.delete_after_link_expires}
|
||||||
toggle={() => console.log("test")}
|
toggle={() =>
|
||||||
|
setDeleteAfterLinkExpiresMutation.mutate({
|
||||||
|
videoId: video.id,
|
||||||
|
delete_after_link_expires:
|
||||||
|
!video.delete_after_link_expires,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/*<div className="mt-3 flex h-6 items-center justify-between">*/}
|
{/*<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>*/}
|
{/* <span>Embed code</span>*/}
|
||||||
{/* <button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">*/}
|
{/* <button className="h-6 rounded border border-solid border-[#d5d9df] bg-white px-[7px] font-medium">*/}
|
||||||
{/* Copy code*/}
|
{/* Copy code*/}
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,30 @@ export const videoRouter = createTRPCRouter({
|
||||||
throw new TRPCError({ code: "FORBIDDEN" });
|
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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
updateVideo,
|
updateVideo,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue