From 3415a2d404b79e0beb3f9be43c108f2d00d40f75 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Thu, 11 Mar 2021 10:04:09 +0000 Subject: [PATCH] --- src/index.ts | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 85617d1..ee5220b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -194,7 +194,7 @@ export default function killTheNewsletter( webApplication.get<{}, HTML, {}, {}, {}>("/", (req, res) => { res.send( layout(html` -
+

("/", (req, res) => { + if ( + req.body.name === undefined || + req.body.name.trim() === "" || + req.body.name.length > 500 + ) + return res.status(400).send( + layout( + html`

+ Error: Missing newsletter name. + Try again. +

` + ) + ); + + const reference = newReference(); + + const created = html` +

+ Sign up for the newsletter with
+ ${reference}@${webApplication.get("email host")} +

+

+ Subscribe to the Atom feed at
+ ${webApplication.get("url")}/feeds/${reference}.xml +

+

+ Don’t share these addresses.
+ They contain an identifier that other people could use to send you spam + and to control your newsletter subscriptions. +

+

Enjoy your readings!

+

+ Create Another Inbox +

+ `; + + const feedId = database.run( + sql`INSERT INTO "feeds" ("reference", "title") VALUES (${reference}, ${req.body.name})` + ).lastInsertRowid; + database.run( + sql` + INSERT INTO "entries" ("reference", "feed", "title", "author", "content") + VALUES (${newReference()}, ${feedId}, ${`“${req.body.name}” inbox created`}, ${"Kill the Newsletter!"}, ${created}) + ` + ); + + res.send( + layout(html` +

+ “${req.body.name}” inbox created + $${created} +

+ `) + ); + }); + const emailApplication = new SMTPServer(); + function newReference(): string { + return cryptoRandomString({ + length: 16, + characters: "abcdefghijklmnopqrstuvwxyz0123456789", + }); + } + return { webApplication, emailApplication }; }