aethex.live/app/api/stream/status/route.ts

82 lines
1.8 KiB
TypeScript

import { PrismaClient } from '@prisma/client'
import { NextRequest, NextResponse } from 'next/server'
const prisma = new PrismaClient()
// GET /api/stream/status - Get live stream status for a channel
export async function GET(request: NextRequest) {
try {
const slug = request.nextUrl.searchParams.get('channel')
if (!slug) {
return NextResponse.json(
{ error: 'Channel slug is required' },
{ status: 400 }
)
}
const channel = await prisma.channel.findUnique({
where: { slug },
select: { id: true },
})
if (!channel) {
return NextResponse.json({ error: 'Channel not found' }, { status: 404 })
}
const stream = await prisma.stream.findFirst({
where: {
channelId: channel.id,
status: 'live',
},
select: {
id: true,
title: true,
description: true,
hlsUrl: true,
rtmpIngestUrl: true,
thumbnailUrl: true,
viewerCount: true,
peakViewers: true,
startedAt: true,
status: true,
},
})
if (!stream) {
return NextResponse.json(
{
isLive: false,
message: 'No active stream',
},
{ status: 200 }
)
}
return NextResponse.json({
isLive: true,
stream,
})
} catch (error) {
console.error('Error checking stream status:', error)
return NextResponse.json(
{ error: 'Failed to check stream status' },
{ status: 500 }
)
}
}
export async function POST(request: NextRequest) {
// Handle stream start/stop events
const body = await request.json();
// TODO: Implement stream control logic
// - Start/stop recording
// - Update stream metadata
// - Trigger notifications
return NextResponse.json({
success: true,
message: 'Stream updated',
});
}