import { blob } from "https://esm.town/v/std/blob?v=11";
import { Hono } from "npm:hono@4.0.8";
const route = new Hono();
route.get("/:name", async (c) => {
const name = c.req.param("name");
const resp = await blob.get(name);
const content = await resp.text();
return c.render(
<>
<form method="POST">
<h1>
<input name="new_name" value={name} />
</h1>
<textarea
style={{
height: "24rem",
}}
name="content"
>
{content}
</textarea>
<input type="submit" value="Submit" />
</form>
</>,
);
});
route.post("/:name", async (c) => {
const name = c.req.param("name");
const { content, new_name }: { content: string; new_name: string } = await c.req.parseBody();
await blob.set(name, content);
if (new_name !== name) {
await blob.move(name, new_name);
}
return c.redirect("/");
});
export default route;