import { PageProps } from "$fresh/server.ts"; import { catcher_async, json_response } from "utils"; import { message_under, add_preset } from "db"; export async function handler( req: Request, props: PageProps ): Promise { if (req.method == "PUT") { return await put(req, props); } else { return new Response(JSON.stringify({ err: "expected a PUT" })); } } async function put(req: Request, props: PageProps): Promise { const json = await catcher_async(() => req.json()); const id = props.params.id; if (!id || json.isNone()) { return json_response({ err: "you SUCK" }, { status: 400 }); } else if (json.unwrap().register_preset) { return json_response( await add_preset(json.unwrap().register_preset, json.unwrap(), id), { status: 300, } ); } else { return json_response(await message_under(json.unwrap(), id), { status: 300, }); } }