parkerdavis-reportcommentnotification.web.val.run
June 22, 2024
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
import { email } from "https://esm.town/v/std/email";
const DELETE_COMMENT_SECRET = Deno.env.get("DELETE_COMMENT_SECRET");
import { type Comment } from "https://esm.town/v/parkerdavis/CommentType";
const baseUrl = "agave-astro.netlify.app";
export default async function(req: Request): Promise<Response> {
if (req.method === "POST") {
const comment = await req.json() as Comment;
console.log("comment", comment);
const fullUrl =
`https://${baseUrl}/api/comments/commentManager?secret=${DELETE_COMMENT_SECRET}&commentId=${comment.id}`;
const modifiedBody = comment.body.replaceAll("\n", "<br>");
await email({
subject: "New Comment Reported",
html: `
<h1>A comment was reported:</h1>
<p>Author: ${comment.author}</p>
<p>Body: <br>${modifiedBody}</p>
<p><a href="${baseUrl}${comment.path}">View Comment</a></p>
<p><a href="${fullUrl}">Manage Comment / Rebuild Site</a></p>
<pre>${JSON.stringify(comment, null, 2)}</pre>
`,
});
return Response.json(JSON.stringify({ ok: true }), { status: 200 });
} else {
return new Response("Hi");
}
}
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 22, 2024