feat: clear

This commit is contained in:
2026-07-08 20:27:54 +02:00
parent 4f16b5737f
commit ce1e57c5f0
16 changed files with 6341 additions and 561 deletions
@@ -1,45 +0,0 @@
import {
applyWhitelistDecision,
parseWhitelistDecision,
} from "@/app/lib/minecraft-whitelist";
export const runtime = "nodejs";
function assertAuthorized(request: Request) {
const token = process.env.MINECRAFT_WHITELIST_ADMIN_TOKEN;
const authorization = request.headers.get("authorization");
if (!token || token.length < 32) {
throw new Error("Token admin whitelist non configuré.");
}
if (authorization !== `Bearer ${token}`) {
throw new Error("Non autorisé.");
}
}
export async function POST(request: Request) {
try {
assertAuthorized(request);
const payload = await request.json();
const { username, decision } = parseWhitelistDecision(payload);
const result = await applyWhitelistDecision(username, decision);
return Response.json({
ok: true,
result,
});
} catch (error) {
const message =
error instanceof Error ? error.message : "Décision impossible.";
return Response.json(
{
ok: false,
message,
},
{ status: message === "Non autorisé." ? 401 : 400 },
);
}
}
+7 -6
View File
@@ -14,16 +14,17 @@ export async function POST(request: Request) {
return Response.json({
ok: true,
message: "Demande envoyée sur Discord.",
message: "Demande envoyée.",
});
} catch (error) {
const message =
error instanceof Error ? error.message : "Impossible d'envoyer la demande.";
const status = message.includes("configuré") ||
message.includes("APP_BASE_URL") ||
message.includes("Secret de revue")
? 503
: 400;
const status =
message.includes("configuré") ||
message.includes("DISCORD_") ||
message.startsWith("Le service de notification a refusé")
? 503
: 400;
return Response.json(
{
@@ -1,90 +0,0 @@
import {
applyWhitelistDecision,
verifyReviewToken,
} from "@/app/lib/minecraft-whitelist";
export const runtime = "nodejs";
function escapeHtml(value: string) {
return value
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#039;");
}
function htmlResponse(title: string, body: string, status = 200) {
return new Response(
`<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex,nofollow" />
<title>${escapeHtml(title)}</title>
<style>
body {
min-height: 100vh;
margin: 0;
display: grid;
place-items: center;
background: #090a0f;
color: #f2efe3;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
main {
width: min(640px, calc(100% - 32px));
border: 4px solid #030303;
background: #252932;
box-shadow: 6px 6px 0 rgb(0 0 0 / 55%);
padding: 28px;
}
h1 {
margin: 0 0 12px;
color: #ffd54a;
font-size: 1.2rem;
}
p {
margin: 0;
line-height: 1.6;
}
</style>
</head>
<body>
<main>
<h1>${escapeHtml(title)}</h1>
<p>${escapeHtml(body)}</p>
</main>
</body>
</html>`,
{
status,
headers: {
"Content-Type": "text/html; charset=utf-8",
"X-Robots-Tag": "noindex, nofollow",
},
},
);
}
export async function GET(request: Request) {
try {
const url = new URL(request.url);
const review = verifyReviewToken(url.searchParams.get("token"));
const result = await applyWhitelistDecision(review.username, review.decision);
return htmlResponse(
review.decision === "accept" ? "Demande acceptée" : "Demande refusée",
result,
);
} catch (error) {
const message =
error instanceof Error ? error.message : "Action impossible.";
return htmlResponse("Action impossible", message, 400);
}
}