1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
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;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 5, 2024