import { blob } from "https://esm.town/v/std/blob?v=10";
import { email } from "https://esm.town/v/std/email?v=9";
import { Hono } from "npm:hono@3.9.2";
const KEY = import.meta.url.split("?")[0];
export async function addComment(str) {
const comments = await blob.getJSON(KEY) as Array<string> ?? [];
comments.push(str);
await blob.setJSON(KEY, comments);
await email({ text: "New Comment Alert!: " + str });
}
export async function getComments() {
return await blob.getJSON(KEY) as Array<string> ?? [];
}
const app = new Hono();
app.get("/", async (c) => c.json(await getComments()));
app.post("/", async (c) => {
const str = await c.req.json();
await addComment(str);
return c.text("Added comment!", 200);
});
export default app.fetch;