From a5e30f48cae657b36626d03c33028968fd3b3e8c Mon Sep 17 00:00:00 2001 From: SujithThirumalaisamy Date: Sun, 8 Sep 2024 20:12:07 +0530 Subject: [PATCH] Added vizolv service endpoint --- src/app/api/admin/services/subtitle/route.ts | 1 - src/app/api/admin/services/vizolv/route.ts | 67 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/app/api/admin/services/vizolv/route.ts diff --git a/src/app/api/admin/services/subtitle/route.ts b/src/app/api/admin/services/subtitle/route.ts index ea7da7c9c..e55fdae15 100644 --- a/src/app/api/admin/services/subtitle/route.ts +++ b/src/app/api/admin/services/subtitle/route.ts @@ -52,7 +52,6 @@ export async function GET(req: NextRequest) { }); return NextResponse.json(video); } catch (error) { - console.log(error); return NextResponse.json( { message: 'Error fetching video' }, { status: 500 }, diff --git a/src/app/api/admin/services/vizolv/route.ts b/src/app/api/admin/services/vizolv/route.ts new file mode 100644 index 000000000..c6e4451b8 --- /dev/null +++ b/src/app/api/admin/services/vizolv/route.ts @@ -0,0 +1,67 @@ +import db from '@/db'; +import { NextRequest, NextResponse } from 'next/server'; + +export async function GET(req: NextRequest) { + const authKey = req.headers.get('Authorization'); + const page = parseInt(req.nextUrl.searchParams.get('page') || '0'); + const limit = parseInt(req.nextUrl.searchParams.get('limit') || '10'); + + if (authKey !== process.env.VIZOLV_SECRET) + return NextResponse.json({ message: 'Unauthorized' }, { status: 403 }); + + try { + const videoMetadata = await db.videoMetadata.findMany({ + where: { + subtitles: { + not: null, + }, + }, + select: { + content: { + select: { + title: true, + description: true, + parentId: true, + courses: { + select: { + courseId: true, + }, + }, + }, + }, + duration: true, + contentId: true, + subtitles: true, + }, + orderBy: { + contentId: 'desc', + }, + take: limit, + skip: page * limit, + }); + + if (!videoMetadata) + return NextResponse.json( + { message: 'Unable to fetch video metadata' }, + { status: 404 }, + ); + + // Parse the video metadata to the format required by Vizolv + const parsedVideoMetadata = videoMetadata.map((video) => ({ + title: video.content.title, + description: video.content.description, + duration: video.duration, + courseId: video.content.courses[0]?.courseId, + folderId: video.content.parentId, + videoId: video.contentId, + captions: video.subtitles, + })); + + return NextResponse.json(parsedVideoMetadata); + } catch (error) { + return NextResponse.json( + { message: 'Error fetching video metadata' }, + { status: 500 }, + ); + } +}