(request: NextRequest)
| 14 | export const dynamic = "force-dynamic"; |
| 15 | |
| 16 | export async function GET(request: NextRequest) { |
| 17 | try { |
| 18 | const user = await getCurrentUser(); |
| 19 | const url = new URL(request.url); |
| 20 | const videoId = url.searchParams.get("videoId") as Video.VideoId; |
| 21 | |
| 22 | if (!user) { |
| 23 | return Response.json({ auth: false }, { status: 401 }); |
| 24 | } |
| 25 | |
| 26 | if (!videoId) { |
| 27 | return Response.json( |
| 28 | { error: true, message: "Video ID not provided" }, |
| 29 | { status: 400 }, |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | const exit = await Effect.gen(function* () { |
| 34 | const videosPolicy = yield* VideosPolicy; |
| 35 | |
| 36 | return yield* Effect.promise(() => |
| 37 | db().select().from(videos).where(eq(videos.id, videoId)), |
| 38 | ).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId))); |
| 39 | }).pipe(provideOptionalAuth, EffectRuntime.runPromiseExit); |
| 40 | |
| 41 | if (Exit.isFailure(exit)) { |
| 42 | return Response.json( |
| 43 | { error: true, message: "Video not found" }, |
| 44 | { status: 404 }, |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | const result = exit.value; |
| 49 | if (result.length === 0 || !result[0]) { |
| 50 | return Response.json( |
| 51 | { error: true, message: "Video not found" }, |
| 52 | { status: 404 }, |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | const video = result[0]; |
| 57 | const metadata: VideoMetadata = (video.metadata as VideoMetadata) || {}; |
| 58 | |
| 59 | if (metadata.summary || metadata.chapters) { |
| 60 | console.log( |
| 61 | `[AI API] Returning existing AI metadata for video ${videoId}`, |
| 62 | ); |
| 63 | return Response.json( |
| 64 | { |
| 65 | processing: false, |
| 66 | title: metadata.aiTitle ?? null, |
| 67 | summary: metadata.summary ?? null, |
| 68 | chapters: metadata.chapters ?? null, |
| 69 | aiGenerationStatus: metadata.aiGenerationStatus ?? null, |
| 70 | }, |
| 71 | { status: 200 }, |
| 72 | ); |
| 73 | } |
nothing calls this directly
no test coverage detected