diff --git a/src/app/api/admin/contentmetadata/route.ts b/src/app/api/admin/contentmetadata/route.ts index d2c262f28..eb22a3947 100644 --- a/src/app/api/admin/contentmetadata/route.ts +++ b/src/app/api/admin/contentmetadata/route.ts @@ -2,20 +2,29 @@ import db from '@/db'; import { NextRequest, NextResponse } from 'next/server'; export const POST = async (req: NextRequest) => { - const { - updates, - contentId, - }: { - updates: any; - contentId: number; - } = await req.json(); - - await db.videoMetadata.update({ - where: { + try { + const { + updates, contentId, - }, - data: updates, - }); - - return NextResponse.json({}, { status: 200 }); + adminPassword, + }: { + updates: any; + contentId: number; + adminPassword: string; + } = await req.json(); + + if (adminPassword !== process.env.ADMIN_SECRET) { + return NextResponse.json({}, { status: 403 }); + } + await db.videoMetadata.update({ + where: { + contentId, + }, + data: updates, + }); + + return NextResponse.json({}, { status: 200 }); + } catch (err) { + return NextResponse.json({}, { status: 500 }); + } }; diff --git a/src/app/api/admin/updatecontent/route.ts b/src/app/api/admin/updatecontent/route.ts index 230ae9f6b..070d10187 100644 --- a/src/app/api/admin/updatecontent/route.ts +++ b/src/app/api/admin/updatecontent/route.ts @@ -2,47 +2,57 @@ import db from '@/db'; import { NextRequest, NextResponse } from 'next/server'; export const POST = async (req: NextRequest) => { - const { - updates, - contentId, - }: { - updates: any; - contentId: number; - } = await req.json(); - - await db.videoMetadata.update({ - where: { + try { + const { + updates, contentId, - }, - data: { - video_360p_1: updates.video_360p, - video_360p_2: updates.video_360p, - video_360p_3: updates.video_360p, - video_360p_4: updates.video_360p, - video_720p_1: updates.video_720p, - video_720p_2: updates.video_720p, - video_720p_3: updates.video_720p, - video_720p_4: updates.video_720p, - video_1080p_1: updates.video_1080p, - video_1080p_2: updates.video_1080p, - video_1080p_3: updates.video_1080p, - video_1080p_4: updates.video_1080p, - /// mp4s + adminPassword, + }: { + updates: any; + contentId: number; + adminPassword: string; + } = await req.json(); - video_1080p_mp4_1: updates.video_1080p_mp4, - video_1080p_mp4_2: updates.video_1080p_mp4, - video_1080p_mp4_3: updates.video_1080p_mp4, - video_1080p_mp4_4: updates.video_1080p_mp4, - video_720p_mp4_1: updates.video_720p_mp4, - video_720p_mp4_2: updates.video_720p_mp4, - video_720p_mp4_3: updates.video_720p_mp4, - video_720p_mp4_4: updates.video_720p_mp4, - video_360p_mp4_1: updates.video_360p_mp4, - video_360p_mp4_2: updates.video_360p_mp4, - video_360p_mp4_3: updates.video_360p_mp4, - video_360p_mp4_4: updates.video_360p_mp4, - }, - }); + if (adminPassword !== process.env.ADMIN_SECRET) { + return NextResponse.json({}, { status: 403 }); + } - return NextResponse.json({}, { status: 200 }); + await db.videoMetadata.update({ + where: { + contentId, + }, + data: { + video_360p_1: updates.video_360p, + video_360p_2: updates.video_360p, + video_360p_3: updates.video_360p, + video_360p_4: updates.video_360p, + video_720p_1: updates.video_720p, + video_720p_2: updates.video_720p, + video_720p_3: updates.video_720p, + video_720p_4: updates.video_720p, + video_1080p_1: updates.video_1080p, + video_1080p_2: updates.video_1080p, + video_1080p_3: updates.video_1080p, + video_1080p_4: updates.video_1080p, + /// mp4s + + video_1080p_mp4_1: updates.video_1080p_mp4, + video_1080p_mp4_2: updates.video_1080p_mp4, + video_1080p_mp4_3: updates.video_1080p_mp4, + video_1080p_mp4_4: updates.video_1080p_mp4, + video_720p_mp4_1: updates.video_720p_mp4, + video_720p_mp4_2: updates.video_720p_mp4, + video_720p_mp4_3: updates.video_720p_mp4, + video_720p_mp4_4: updates.video_720p_mp4, + video_360p_mp4_1: updates.video_360p_mp4, + video_360p_mp4_2: updates.video_360p_mp4, + video_360p_mp4_3: updates.video_360p_mp4, + video_360p_mp4_4: updates.video_360p_mp4, + }, + }); + + return NextResponse.json({}, { status: 200 }); + } catch (err) { + return NextResponse.json({}, { status: 500 }); + } }; diff --git a/src/components/admin/UpdateVideoClient.tsx b/src/components/admin/UpdateVideoClient.tsx index 83eba6e25..72dab147a 100644 --- a/src/components/admin/UpdateVideoClient.tsx +++ b/src/components/admin/UpdateVideoClient.tsx @@ -35,6 +35,7 @@ export const UpdateVideoClient = ({ const [pdfLink, setPdfLink] = useState(''); const [vttLink, setVttLink] = useState(''); + const [adminPassword, setAdminPassword] = useState(''); return (
@@ -108,10 +109,17 @@ export const UpdateVideoClient = ({ }} placeholder={'m3u8 360p'} /> + + setAdminPassword(e.target.value)} + />