34 lines
1,020 B
TypeScript
34 lines
1,020 B
TypeScript
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<Response> {
|
|
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<Response> {
|
|
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,
|
|
});
|
|
}
|
|
}
|