-
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.
- Loading branch information
1 parent
881b135
commit a5e30f4
Showing
2 changed files
with
67 additions
and
1 deletion.
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
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 }, | ||
); | ||
} | ||
} |