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);