Update code
This commit is contained in:
@@ -5,12 +5,51 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const revalidate = 0;
|
||||
|
||||
// --- GET pour raw ou JSON ---
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id: pasteId } = await context.params; // ✅ await obligatoire
|
||||
|
||||
if (!pasteId) {
|
||||
return NextResponse.json({ error: 'Invalid ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
const paste = await prisma.paste.findUnique({ where: { id: pasteId } });
|
||||
if (!paste) {
|
||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
// Si paste protégé, on bloque le GET
|
||||
if (paste.password) {
|
||||
return NextResponse.json({ error: 'This paste is protected' }, { status: 403 });
|
||||
}
|
||||
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
if (searchParams.get('raw') === '1') {
|
||||
return new NextResponse(paste.content, {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
id: paste.id,
|
||||
title: paste.title,
|
||||
content: paste.content,
|
||||
createdAt: paste.createdAt,
|
||||
views: paste.views,
|
||||
protected: !!paste.password,
|
||||
});
|
||||
}
|
||||
|
||||
// --- POST pour récupérer en validant le password ---
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
context: { params: { id: string } }
|
||||
context: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { params } = context;
|
||||
const pasteId = params.id;
|
||||
const { id: pasteId } = await context.params; // ✅ ici aussi
|
||||
|
||||
const { password = '' } = await request.json();
|
||||
|
||||
@@ -65,4 +104,4 @@ export async function POST(
|
||||
return NextResponse.json(payload, {
|
||||
headers: { 'Cache-Control': 'no-store' },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user