From bbb19beb2229c0bc95c96b2b1b7096e7c0590445 Mon Sep 17 00:00:00 2001 From: hkirat Date: Wed, 14 Aug 2024 05:58:44 +0530 Subject: [PATCH] Added admin routes --- .../[...moduleId]}/page.tsx | 33 ++-- src/app/admin/content/[courseId]/page.tsx | 57 +++++++ src/app/api/admin/contentmetadata/route.ts | 21 +++ src/app/api/admin/updatecontent/route.ts | 48 ++++++ src/app/api/discord/redirect/cohort3/route.ts | 22 +-- src/app/error.tsx | 2 - src/components/admin/CourseContent.tsx | 12 +- src/components/admin/UpdateVideoClient.tsx | 148 ++++++++++++++++++ src/utiles/appx.ts | 3 +- 9 files changed, 306 insertions(+), 40 deletions(-) rename src/app/admin/content/{[...courseId] => [courseId]/[...moduleId]}/page.tsx (60%) create mode 100644 src/app/admin/content/[courseId]/page.tsx create mode 100644 src/app/api/admin/contentmetadata/route.ts create mode 100644 src/app/api/admin/updatecontent/route.ts create mode 100644 src/components/admin/UpdateVideoClient.tsx diff --git a/src/app/admin/content/[...courseId]/page.tsx b/src/app/admin/content/[courseId]/[...moduleId]/page.tsx similarity index 60% rename from src/app/admin/content/[...courseId]/page.tsx rename to src/app/admin/content/[courseId]/[...moduleId]/page.tsx index 5d9cef4f6..25d8bf512 100644 --- a/src/app/admin/content/[...courseId]/page.tsx +++ b/src/app/admin/content/[courseId]/[...moduleId]/page.tsx @@ -1,33 +1,29 @@ -import { - getCourse, - getCourseContent, - getCurrentContentType, -} from '@/db/course'; +import { getCourse, getFullCourseContent } from '@/db/course'; import { AddContent } from '@/components/admin/AddContent'; import { AdminCourseContent } from '@/components/admin/CourseContent'; +import findContentById from '@/lib/find-content-by-id'; +import { UpdateVideoClient } from '@/components/admin/UpdateVideoClient'; export default async function UpdateCourseContent({ params, }: { - params: { courseId: string[] }; + params: { moduleId: string[]; courseId: string }; }) { - const courseId = params.courseId[0]; - const rest = params.courseId.slice(1); + const courseId = params.courseId; + const rest = params.moduleId; const course = await getCourse(parseInt(courseId, 10)); - const courseContent = await getCourseContent( - parseInt(courseId, 10), - rest.map((x: string) => parseInt(x, 10)), - ); - const contentType = await getCurrentContentType( - parseInt(courseId, 10), - rest.map((x: string) => parseInt(x, 10)), + const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10)); + const courseContent = findContentById( + fullCourseContent, + rest.map((x) => parseInt(x, 10)), ); + const contentType = + courseContent?.length === 1 ? courseContent[0]?.type : 'folder'; if (contentType === 'video') { return (
- {/* */} - Video +
); } @@ -50,7 +46,8 @@ export default async function UpdateCourseContent({ parentContentId={parseFloat(rest[rest.length - 1])} /> ({ + rest={rest} + courseContent={courseContent?.map((x: any) => ({ title: x?.title || '', image: x?.thumbnail || '', id: x?.id || 0, diff --git a/src/app/admin/content/[courseId]/page.tsx b/src/app/admin/content/[courseId]/page.tsx new file mode 100644 index 000000000..eeb28977d --- /dev/null +++ b/src/app/admin/content/[courseId]/page.tsx @@ -0,0 +1,57 @@ +import { getCourse, getFullCourseContent } from '@/db/course'; +import { AddContent } from '@/components/admin/AddContent'; +import { AdminCourseContent } from '@/components/admin/CourseContent'; +import findContentById from '@/lib/find-content-by-id'; + +export default async function UpdateCourseContent({ + params, +}: { + params: { courseId: string }; +}) { + const courseId = params.courseId; + const rest: string[] = []; + const course = await getCourse(parseInt(courseId, 10)); + const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10)); + const courseContent = findContentById( + fullCourseContent, + rest.map((x) => parseInt(x, 10)), + ); + const contentType = + courseContent?.length === 1 ? courseContent[0]?.type : 'folder'; + + if (contentType === 'video') { + return ( +
+ Video +
+ ); + } + + if (contentType === 'notion') { + return ( +
+ Notion doc +
+ ); + } + + return ( +
+ {course?.title} +
Content
+ + ({ + title: x?.title || '', + image: x?.thumbnail || '', + id: x?.id || 0, + }))} + courseId={parseInt(courseId, 10)} + /> +
+ ); +} diff --git a/src/app/api/admin/contentmetadata/route.ts b/src/app/api/admin/contentmetadata/route.ts new file mode 100644 index 000000000..d2c262f28 --- /dev/null +++ b/src/app/api/admin/contentmetadata/route.ts @@ -0,0 +1,21 @@ +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: { + contentId, + }, + data: updates, + }); + + return NextResponse.json({}, { status: 200 }); +}; diff --git a/src/app/api/admin/updatecontent/route.ts b/src/app/api/admin/updatecontent/route.ts new file mode 100644 index 000000000..230ae9f6b --- /dev/null +++ b/src/app/api/admin/updatecontent/route.ts @@ -0,0 +1,48 @@ +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: { + 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 }); +}; diff --git a/src/app/api/discord/redirect/cohort3/route.ts b/src/app/api/discord/redirect/cohort3/route.ts index c528ea746..76d7e1ec5 100644 --- a/src/app/api/discord/redirect/cohort3/route.ts +++ b/src/app/api/discord/redirect/cohort3/route.ts @@ -30,7 +30,7 @@ const WEB3_ROLES: string[] = [ '1264392616171016334', ]; -const COHORT3_APPX_IDS = ['12', '13', '14', '15', '16']; +const COHORT3_IDS = [13, 14, 15]; export async function POST(req: NextRequest) { const session = await getServerSession(authOptions); @@ -64,35 +64,25 @@ export async function POST(req: NextRequest) { ); } const purchases = res.courses.filter((purchase: any) => - COHORT3_APPX_IDS.includes(purchase.appxCourseId), + COHORT3_IDS.includes(purchase.id), ); - const purchaseCourseIds = purchases.map( - (purchase: any) => purchase.appxCourseId, - ); + const purchaseCourseIds = purchases.map((purchase: any) => purchase.id); const roles: string[] = []; let hasWebDev = false; let hasDevOps = false; let hasWeb3 = false; - if ( - purchaseCourseIds.includes('12') || - purchaseCourseIds.includes('14') || - purchaseCourseIds.includes('15') - ) { + if (purchaseCourseIds.includes(14)) { hasWebDev = true; } - if ( - purchaseCourseIds.includes('12') || - purchaseCourseIds.includes('14') || - purchaseCourseIds.includes('16') - ) { + if (purchaseCourseIds.includes(15)) { hasDevOps = true; } - if (purchaseCourseIds.includes('13') || purchaseCourseIds.includes('14')) { + if (purchaseCourseIds.includes(13)) { hasWeb3 = true; } diff --git a/src/app/error.tsx b/src/app/error.tsx index db6d36727..79bb12187 100644 --- a/src/app/error.tsx +++ b/src/app/error.tsx @@ -1,13 +1,11 @@ 'use client'; -import { Button } from '@/components/ui/button'; import { InfoIcon } from 'lucide-react'; import Link from 'next/link'; import { useEffect } from 'react'; export default function ErrorPage({ error, - reset, }: { error: Error & { digest?: string }; reset: () => void; diff --git a/src/components/admin/CourseContent.tsx b/src/components/admin/CourseContent.tsx index 67db3973e..2546d342c 100644 --- a/src/components/admin/CourseContent.tsx +++ b/src/components/admin/CourseContent.tsx @@ -5,6 +5,7 @@ import { ContentCard } from '../ContentCard'; export const AdminCourseContent = ({ courseContent, courseId, + rest, }: { courseId: number; courseContent: { @@ -12,26 +13,31 @@ export const AdminCourseContent = ({ image: string; id: number; }[]; + rest: string[]; }) => { const router = useRouter(); + let updatedRoute = `/admin/content/${courseId}`; + for (let i = 0; i < rest.length; i++) { + updatedRoute += `/${rest[i]}`; + } return (
Course content
- {courseContent.map( + {courseContent?.map( (content: { image: string; id: number; title: string }) => ( { - router.push(`/admin/content/${courseId}/${content.id}`); + router.push(`${updatedRoute}/${content.id}`); }} key={content.id} /> ), - )} + ) ?? []}
); diff --git a/src/components/admin/UpdateVideoClient.tsx b/src/components/admin/UpdateVideoClient.tsx new file mode 100644 index 000000000..7d9939be2 --- /dev/null +++ b/src/components/admin/UpdateVideoClient.tsx @@ -0,0 +1,148 @@ +'use client'; +import { useState } from 'react'; +import axios from 'axios'; + +export const UpdateVideoClient = ({ + content, +}: { + content: { + type: 'video'; + id: number; + title: string; + thumbnail: string; + description: string; + markAsCompleted: boolean; + }; +}) => { + const [link1080, setLink1080] = useState(''); + const [link720, setLink720] = useState(''); + const [link360, setLink360] = useState(''); + + const [link1080_mp4, setLink1080_mp4] = useState(''); + const [link720_mp4, setLink720_mp4] = useState(''); + const [link360_mp4, setLink360_mp4] = useState(''); + + const [pdfLink, setPdfLink] = useState(''); + const [vttLink, setVttLink] = useState(''); + + return ( + <> + m3u8 links + { + setLink1080(e.target.value); + setLink720(e.target.value.replace('1080', '720')); + setLink360(e.target.value.replace('1080', '360')); + }} + placeholder={'m3u8 1080p'} + /> + { + setLink720(e.target.value); + }} + placeholder={'m3u8 720p'} + /> + { + setLink360(e.target.value); + }} + placeholder={'m3u8 360p'} + /> +
+ Mp4 links + { + setLink1080_mp4(e.target.value); + setLink720_mp4(e.target.value.replace('1080', '720')); + setLink360_mp4(e.target.value.replace('1080', '360')); + }} + placeholder={'m3u8 1080p'} + /> + { + setLink720_mp4(e.target.value); + }} + placeholder={'m3u8 720p'} + /> + { + setLink360_mp4(e.target.value); + }} + placeholder={'m3u8 360p'} + /> + + { + setPdfLink(e.target.value); + }} + placeholder={'pdf link'} + /> + +
+ { + setVttLink(e.target.value); + }} + placeholder={'vtt link'} + /> + + + ); +}; diff --git a/src/utiles/appx.ts b/src/utiles/appx.ts index f99ad8b34..5176782f5 100644 --- a/src/utiles/appx.ts +++ b/src/utiles/appx.ts @@ -75,9 +75,10 @@ function getExtraCourses(currentCourses: Course[], allCourses: Course[]) { if (hasWeb3) { userCourses.push(allCourses.find((x) => x.id === 13)!); } + return userCourses; } - return []; + return initialCourses; } interface CoursesError {