Update code

This commit is contained in:
UltraLionFr
2025-08-20 14:14:33 +02:00
parent 174cf5ef60
commit 0c1a0d74d7
53 changed files with 3830 additions and 373 deletions
+45
View File
@@ -0,0 +1,45 @@
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import { prisma } from '@/lib/prisma';
import { getServerSession } from 'next-auth';
import { NextResponse } from 'next/server';
export async function GET(req: Request) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json([], { status: 401 });
}
const { searchParams } = new URL(req.url);
const page = parseInt(searchParams.get('page') || '1', 10);
const perPage = parseInt(searchParams.get('perPage') || '10', 10);
const skip = (page - 1) * perPage;
const search = searchParams.get('q') || '';
const filter = {
createdBy: session.user.id,
...(search
? {
title: {
contains: search,
mode: 'insensitive',
},
}
: {}),
};
const [pastes, total] = await Promise.all([
prisma.paste.findMany({
where: filter,
orderBy: { createdAt: 'desc' },
skip,
take: perPage,
}),
prisma.paste.count({
where: filter,
}),
]);
return NextResponse.json({ pastes, total });
}