Files
Şahan Hasret 76c31274d5 Database
2025-11-21 17:46:30 +03:00

58 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
import { withAuth } from '@/lib/auth';
// GET - Aktif canlı yayın bilgisini getir
export async function GET() {
try {
const liveStream = await prisma.liveStream.findFirst({
where: { active: true },
});
return NextResponse.json(liveStream || { active: false, url: '', title: '' });
} catch (error) {
console.error('Live stream fetch error:', error);
return NextResponse.json(
{ error: 'Canlı yayın bilgisi alınırken hata oluştu' },
{ status: 500 }
);
}
}
// POST - Canlı yayın ayarlarını güncelle (Auth gerekli)
export async function POST(request: NextRequest) {
return withAuth(request, async () => {
try {
const data = await request.json();
// Önce tüm canlı yayınları pasif yap
await prisma.liveStream.updateMany({
data: { active: false },
});
// Yeni ayarları oluştur veya güncelle
const liveStream = await prisma.liveStream.upsert({
where: { id: data.id || 0 },
update: {
url: data.url,
active: data.active,
title: data.title,
},
create: {
url: data.url,
active: data.active,
title: data.title,
},
});
return NextResponse.json(liveStream);
} catch (error) {
console.error('Live stream update error:', error);
return NextResponse.json(
{ error: 'Canlı yayın güncellenirken hata oluştu' },
{ status: 500 }
);
}
});
}