Skip to content

Commit

Permalink
Added vizolv service endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
SujithThirumalaisamy committed Sep 8, 2024
1 parent 881b135 commit a5e30f4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/app/api/admin/services/subtitle/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
67 changes: 67 additions & 0 deletions src/app/api/admin/services/vizolv/route.ts
Original file line number Diff line number Diff line change
@@ -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 },
);
}
}

0 comments on commit a5e30f4

Please sign in to comment.