Database
This commit is contained in:
57
app/api/live-stream/route.ts
Normal file
57
app/api/live-stream/route.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user