diff options
| author | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
| commit | fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch) | |
| tree | aa8f34e1692bd2d638a2c996eeadb58671d07aea /routes/email.ts | |
| parent | 00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff) | |
| download | coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip | |
typescript
Diffstat (limited to 'routes/email.ts')
| -rw-r--r-- | routes/email.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/routes/email.ts b/routes/email.ts new file mode 100644 index 00000000..63c88ab0 --- /dev/null +++ b/routes/email.ts @@ -0,0 +1,61 @@ +import { bail } from "$lib/utils"; +import got from "got"; +import config from "$config"; +import { l, warn } from "$lib/logging"; +import { SESClient } from "@aws-sdk/client-ses"; +import { SendEmailCommand } from "@aws-sdk/client-ses"; + +export default { + async send({ body }, res) { + try { + let { email, message, username, token: response } = body; + + let Charset = "UTF-8"; + + let { recaptcha: secret } = config; + let { success } = await got + .post("https://www.google.com/recaptcha/api/siteverify", { + form: { + secret, + response, + }, + }) + .json(); + + if (success || response === config.adminpass) { + delete body.token; + + warn("support request from", email); + let client = new SESClient({ region: "us-east-2" }); + await client.send( + new SendEmailCommand({ + Destination: { + CcAddresses: [], + ToAddresses: [config.support], + }, + Message: { + Body: { + Html: { Charset, Data: message.replace(/\n/g, "<br>") }, + Text: { Charset, Data: message }, + }, + Subject: { + Charset, + Data: + body.subject || + "Support Request" + (username ? " From " + username : ""), + }, + }, + ReplyToAddresses: [email], + Source: config.support, + }), + ); + + res.send({ ok: true }); + } else { + bail(res, "failed captcha"); + } + } catch (e) { + console.log(e); + } + }, +}; |
