Skip to content

Commit

Permalink
feat: add contact notification email
Browse files Browse the repository at this point in the history
  • Loading branch information
cptchloroplast committed Oct 30, 2024
1 parent ee06fbc commit 14c9673
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "npm-run-all build:blog test",
"build:blog": "astro build",
"build:worker": "npx wrangler deploy src/functions/index.ts --dry-run --outdir build",
"build:worker": "wrangler deploy src/functions/index.ts --dry-run --outdir build",
"migrate:local": "wrangler d1 migrations apply blog --local",
"migrate:remote": "wrangler d1 migrations apply blog --remote",
"start": "npm-run-all migrate:local start:blog",
Expand Down
7 changes: 6 additions & 1 deletion src/pages/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export async function POST(context: APIContext) {
message: "No robots allowed!"
})

await context.locals.runtime.env.BLOG.put(`messages/${data.email}/${new Date().toISOString()}.txt`, data.message)
const key = `messages/${data.email}/${new Date().toISOString()}.txt`
await context.locals.runtime.env.BLOG.put(key, data.message)
await EmailService(context.locals.runtime.env).send({
subject: `New message from ${data.email}`,
body: `Key: ${key}\n\n---\n\n${data.message}`,
})

return json({
ok: true,
Expand Down
5 changes: 3 additions & 2 deletions src/services/EmailService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Problem } from "@okkema/worker"

export type Email = {
to: {
to?: {
email: string
}[]
subject: string
html: string
html?: string
body?: string
}

type EmailService = {
Expand Down

0 comments on commit 14c9673

Please sign in to comment.