-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1161 from SujithThirumalaisamy/new
Added vizolv service endpoint
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import db from '@/db'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export async function GET(req: NextRequest) { | ||
const authKey = req.headers.get('Authorization'); | ||
const videoId = req.nextUrl.searchParams.get('videoId'); | ||
|
||
if (authKey !== process.env.VIZOLV_SECRET) | ||
return NextResponse.json({ message: 'Unauthorized' }, { status: 403 }); | ||
|
||
if (!videoId) | ||
return NextResponse.json( | ||
{ message: 'No videoId provided' }, | ||
{ status: 400 }, | ||
); | ||
|
||
try { | ||
const videoMetadata = await db.videoMetadata.findFirst({ | ||
where: { | ||
id: parseInt(videoId, 10), | ||
}, | ||
select: { | ||
content: { | ||
select: { | ||
title: true, | ||
description: true, | ||
parentId: true, | ||
courses: { | ||
select: { | ||
courseId: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
duration: true, | ||
contentId: true, | ||
subtitles: true, | ||
}, | ||
}); | ||
|
||
if (!videoMetadata) | ||
return NextResponse.json( | ||
{ message: 'Unable to fetch video metadata' }, | ||
{ status: 404 }, | ||
); | ||
|
||
return NextResponse.json(videoMetadata); | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ message: 'Error fetching video metadata' }, | ||
{ status: 500 }, | ||
); | ||
} | ||
} |