Add user catch submission and moderation workflow
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import type { APIRoute } from "astro";
|
||||
const base = import.meta.env.API_INTERNAL_URL || "http://localhost:8000";
|
||||
export const POST: APIRoute = async ({ request, redirect }) => {
|
||||
const form = await request.formData();
|
||||
const text = (name: string) => String(form.get(name) || "").trim() || null;
|
||||
const number = (name: string) => text(name) ? Number(text(name)) : null;
|
||||
const payload = { fish_slug: String(form.get("fish_slug") || ""), waterbody_slug: String(form.get("waterbody_slug") || ""), x: Number(form.get("x")), y: Number(form.get("y")), weight_g: Number(form.get("weight_g")), bait_name: text("bait_name"), fishing_method: text("fishing_method"), retrieve_method: text("retrieve_method"), retrieve_speed: number("retrieve_speed"), player_name: text("player_name"), comment: text("comment"), website: String(form.get("website") || "") };
|
||||
try { const response = await fetch(`${base}/api/v1/catch-reports`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(payload) }); return redirect(response.ok ? "/report?state=sent" : "/report?state=error", 303); }
|
||||
catch { return redirect("/report?state=error", 303); }
|
||||
};
|
||||
Reference in New Issue
Block a user