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
46
47
48
49
50
51
52
53
54
55
56
57
/** @jsxImportSource npm:hono@3/jsx */
import valTownBadge from "https://esm.town/v/jxnblk/valTownBadgeMiddleware";
import { sqlite } from "https://esm.town/v/std/sqlite";
import { Filter } from "npm:content-checker";
import { Hono } from "npm:hono@3";
const app = new Hono();
const filter = new Filter();
sqlite.execute(`
delete from messages_safe (
id INTEGER PRIMARY KEY AUTOINCREMENT,
content TEXT,
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`);
app.get("/", async (c) => {
return c.html(
<>
<head>
<title>Safe Message Board</title>
</head>
<body>
<main>
<h1>Safe Message Board</h1>
<p>
This message board uses <a href="https://www.npmjs.com/package/content-checker">content-checker</a>{" "}
to sanitize your messages. Do your worst!
</p>
<form method="POST">
<label>
Your Message:
<input type="text" name="content" required />
</label>
<button type="submit">Submit</button>
</form>
<section>
Nevermind! This was a bad idea. People very easily found ways to be terrible.
</section>
</main>
</body>
</>,
);
});
app.post("/", async (c) => {
const form = await c.req.formData();
let content = form.get("content") as string;
await sqlite.execute({
sql: `INSERT INTO messages (content) VALUES (?)`,
args: [content],
});
return c.redirect("/");
});
export default valTownBadge(app.fetch, import.meta.url);