import { blob } from "https://esm.town/v/std/blob?v=11";
import { Hono } from "npm:hono@4.0.8";
import { HTTPException } from "npm:hono@4.0.8/http-exception";
const route = new Hono();
route.get("/", (c) => {
return c.render(
<form method="POST">
<label for="key">Key</label>
<input name="key" type="text" />
<label for="content">Content</label>
<textarea style="height: 60vh;" name="content" />
<input type="submit" value="Create" />
</form>,
);
});
route.post("/", async (c) => {
const { key, content }: { key: string; content: string } = await c.req.parseBody();
try {
await blob.get(key);
} catch (_) {
await blob.set(key, content);
return c.redirect("/");
}
throw new HTTPException(400, { message: `key ${key} already exists` });
});
export default route;