Initial commit

This commit is contained in:
twotalesanimation
2026-06-11 10:46:09 +02:00
commit 81ad7e4ea9
223 changed files with 39530 additions and 0 deletions
@@ -0,0 +1,62 @@
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ commentId: string }> }
) {
const { commentId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
try {
const { content } = await request.json();
if (!content || typeof content !== 'string' || content.trim().length === 0) {
return NextResponse.json(
{ error: 'Non-empty content is required' },
{ status: 400 }
);
}
// Verify comment exists
const comment = await prisma.comment.findUnique({
where: { id: commentId },
});
if (!comment) {
return NextResponse.json({ error: 'Comment not found' }, { status: 404 });
}
const reply = await prisma.commentReply.create({
data: {
commentId,
userId: (session.user as any).id,
content: content.trim(),
},
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
},
});
return NextResponse.json(reply, { status: 201 });
} catch (error) {
console.error('Failed to create reply:', error);
return NextResponse.json(
{ error: 'Failed to create reply' },
{ status: 500 }
);
}
}
+36
View File
@@ -0,0 +1,36 @@
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ commentId: string }> }
) {
const { commentId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const role = (session.user as any).role;
if (role !== 'admin' && role !== 'superadmin') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
try {
// Delete the comment and its replies (cascade via Prisma)
const comment = await prisma.comment.delete({
where: { id: commentId },
});
return NextResponse.json({ success: true });
} catch (error) {
console.error('Failed to delete comment:', error);
return NextResponse.json(
{ error: 'Failed to delete comment' },
{ status: 500 }
);
}
}
+35
View File
@@ -0,0 +1,35 @@
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ replyId: string }> }
) {
const { replyId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const role = (session.user as any).role;
if (role !== 'admin' && role !== 'superadmin') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
try {
const reply = await prisma.commentReply.delete({
where: { id: replyId },
});
return NextResponse.json({ success: true });
} catch (error) {
console.error('Failed to delete reply:', error);
return NextResponse.json(
{ error: 'Failed to delete reply' },
{ status: 500 }
);
}
}
+123
View File
@@ -0,0 +1,123 @@
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function GET(request: NextRequest) {
const videoId = request.nextUrl.searchParams.get('videoId');
if (!videoId) {
return NextResponse.json(
{ error: 'videoId is required' },
{ status: 400 }
);
}
try {
const comments = await prisma.comment.findMany({
where: { videoId },
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
replies: {
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
},
orderBy: {
createdAt: 'asc',
},
},
},
orderBy: {
createdAt: 'desc',
},
});
return NextResponse.json(comments);
} catch (error) {
console.error('Failed to fetch comments:', error);
return NextResponse.json(
{ error: 'Failed to fetch comments' },
{ status: 500 }
);
}
}
export async function POST(request: NextRequest) {
const session = await getServerSession(authOptions);
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
try {
const { videoId, content } = await request.json();
if (!videoId || !content || typeof content !== 'string' || content.trim().length === 0) {
return NextResponse.json(
{ error: 'videoId and non-empty content are required' },
{ status: 400 }
);
}
// Verify video exists
const video = await prisma.video.findUnique({
where: { id: videoId },
});
if (!video) {
return NextResponse.json({ error: 'Video not found' }, { status: 404 });
}
const comment = await prisma.comment.create({
data: {
videoId,
userId: (session.user as any).id,
content: content.trim(),
},
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
replies: {
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
},
},
},
});
return NextResponse.json(comment, { status: 201 });
} catch (error) {
console.error('Failed to create comment:', error);
return NextResponse.json(
{ error: 'Failed to create comment' },
{ status: 500 }
);
}
}