mirror of
https://forgejo.ultimateplayer.xyz/ultimateplayer1999/dcordabuse.git
synced 2026-09-15 20:55:49 -04:00
Fix reports endpoint and added user api endpoint
This commit is contained in:
@@ -49,7 +49,7 @@ export async function POST(req: Request) {
|
||||
|
||||
const { discordId, username, category, description, evidenceUrl } = parsed.data;
|
||||
|
||||
const report = await prisma.$transaction(async (tx) => {
|
||||
const report = await prisma.$transaction(async (tx: any) => {
|
||||
await tx.reportedUser.upsert({
|
||||
where: { discordId },
|
||||
create: { discordId, username },
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { authenticateRequest } from "@/lib/auth";
|
||||
import { checkRateLimit } from "@/lib/rateLimit";
|
||||
|
||||
/**
|
||||
* GET /api/v1/users/:discordId
|
||||
* Geeft alleen APPROVED reports terug — pending/rejected reports zijn nooit
|
||||
* publiek zichtbaar via deze endpoint, ook niet voor SUBMITTER keys.
|
||||
*/
|
||||
export async function GET(
|
||||
req: Request,
|
||||
{ params }: { params: { discordId: string } }
|
||||
) {
|
||||
const auth = await authenticateRequest(req);
|
||||
if (!auth.ok) return NextResponse.json({ error: auth.error }, { status: auth.status });
|
||||
|
||||
const rate = await checkRateLimit(auth.apiKey);
|
||||
if (!rate.allowed) {
|
||||
return NextResponse.json(
|
||||
{ error: "Rate limit overschreden" },
|
||||
{ status: 429, headers: { "Retry-After": String(Math.ceil((rate.retryAfterMs ?? 0) / 1000)) } }
|
||||
);
|
||||
}
|
||||
|
||||
const { discordId } = params;
|
||||
if (!/^\d{17,20}$/.test(discordId)) {
|
||||
return NextResponse.json({ error: "Ongeldig Discord user ID" }, { status: 400 });
|
||||
}
|
||||
|
||||
const user = await prisma.reportedUser.findUnique({
|
||||
where: { discordId },
|
||||
include: {
|
||||
reports: {
|
||||
where: { status: "APPROVED" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
select: {
|
||||
id: true,
|
||||
category: true,
|
||||
description: true,
|
||||
evidenceUrl: true,
|
||||
createdAt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!user || user.reports.length === 0) {
|
||||
return NextResponse.json({ discordId, found: false, reports: [] });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
discordId,
|
||||
found: true,
|
||||
username: user.username,
|
||||
reportCount: user.reports.length,
|
||||
reports: user.reports,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user