Initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// app/api/admin/videos/[videoId]/instant-access/route.ts
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth-options';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export async function PATCH(req: Request, context: any) {
|
||||
try {
|
||||
// Unwrap params
|
||||
let params = context?.params;
|
||||
if (typeof params?.then === 'function') params = await params;
|
||||
|
||||
const videoId = params?.videoId;
|
||||
if (!videoId)
|
||||
return NextResponse.json({ error: 'videoId required' }, { status: 400 });
|
||||
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.email)
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
// Check admin role
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: session.user.email },
|
||||
select: { id: true, role: true },
|
||||
});
|
||||
|
||||
if (!user || (user.role !== 'admin' && user.role !== 'superadmin'))
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const { instantAccess } = body ?? {};
|
||||
|
||||
if (typeof instantAccess !== 'boolean')
|
||||
return NextResponse.json(
|
||||
{ error: 'instantAccess boolean value required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
// Update the video
|
||||
const video = await prisma.video.update({
|
||||
where: { id: videoId },
|
||||
data: { instantAccess },
|
||||
select: { id: true, title: true, instantAccess: true, locked: true },
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, video });
|
||||
} catch (err: any) {
|
||||
console.error('admin instant-access PATCH error', err);
|
||||
return NextResponse.json(
|
||||
{ error: err?.message ?? 'server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(req: Request, context: any) {
|
||||
try {
|
||||
// Unwrap params
|
||||
let params = context?.params;
|
||||
if (typeof params?.then === 'function') params = await params;
|
||||
|
||||
const videoId = params?.videoId;
|
||||
if (!videoId)
|
||||
return NextResponse.json({ error: 'videoId required' }, { status: 400 });
|
||||
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.email)
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
// Check admin role
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: session.user.email },
|
||||
select: { id: true, role: true },
|
||||
});
|
||||
|
||||
if (!user || (user.role !== 'admin' && user.role !== 'superadmin'))
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
|
||||
// Get the video
|
||||
const video = await prisma.video.findUnique({
|
||||
where: { id: videoId },
|
||||
select: { id: true, title: true, instantAccess: true, locked: true },
|
||||
});
|
||||
|
||||
if (!video)
|
||||
return NextResponse.json({ error: 'video not found' }, { status: 404 });
|
||||
|
||||
return NextResponse.json({ video });
|
||||
} catch (err: any) {
|
||||
console.error('admin instant-access GET error', err);
|
||||
return NextResponse.json(
|
||||
{ error: err?.message ?? 'server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// app/api/admin/videos/[videoId]/locked/route.ts
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth-options';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export async function PATCH(req: Request, context: any) {
|
||||
try {
|
||||
// Unwrap params
|
||||
let params = context?.params;
|
||||
if (typeof params?.then === 'function') params = await params;
|
||||
|
||||
const videoId = params?.videoId;
|
||||
if (!videoId)
|
||||
return NextResponse.json({ error: 'videoId required' }, { status: 400 });
|
||||
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.email)
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
// Check admin role
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: session.user.email },
|
||||
select: { id: true, role: true },
|
||||
});
|
||||
|
||||
if (!user || (user.role !== 'admin' && user.role !== 'superadmin'))
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const { locked } = body ?? {};
|
||||
|
||||
if (typeof locked !== 'boolean')
|
||||
return NextResponse.json(
|
||||
{ error: 'locked boolean value required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
// Update the video
|
||||
const video = await prisma.video.update({
|
||||
where: { id: videoId },
|
||||
data: { locked },
|
||||
select: { id: true, title: true, locked: true, instantAccess: true },
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, video });
|
||||
} catch (err: any) {
|
||||
console.error('admin locked PATCH error', err);
|
||||
return NextResponse.json(
|
||||
{ error: err?.message ?? 'server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(req: Request, context: any) {
|
||||
try {
|
||||
// Unwrap params
|
||||
let params = context?.params;
|
||||
if (typeof params?.then === 'function') params = await params;
|
||||
|
||||
const videoId = params?.videoId;
|
||||
if (!videoId)
|
||||
return NextResponse.json({ error: 'videoId required' }, { status: 400 });
|
||||
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.email)
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
// Check admin role
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: session.user.email },
|
||||
select: { id: true, role: true },
|
||||
});
|
||||
|
||||
if (!user || (user.role !== 'admin' && user.role !== 'superadmin'))
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
|
||||
// Get the video
|
||||
const video = await prisma.video.findUnique({
|
||||
where: { id: videoId },
|
||||
select: { id: true, title: true, locked: true, instantAccess: true },
|
||||
});
|
||||
|
||||
if (!video)
|
||||
return NextResponse.json({ error: 'video not found' }, { status: 404 });
|
||||
|
||||
return NextResponse.json({ video });
|
||||
} catch (err: any) {
|
||||
console.error('admin locked GET error', err);
|
||||
return NextResponse.json(
|
||||
{ error: err?.message ?? 'server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user