Skip to content

Commit

Permalink
feat(mpc): add ping edge function
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Nov 21, 2024
1 parent 054782a commit 5374b3e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mpc/edge/supabase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Supabase
.branches
.temp
.env
49 changes: 49 additions & 0 deletions mpc/edge/supabase/functions/ping/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const resendSecret = Deno.env.get("RESEND_SECRET")
const resendApiKey = Deno.env.get("RESEND_API_KEY")

const handler = async (request: Request): Promise<Response> => {
const { secret, email } = await request.json()
if (secret !== resendSecret) {
return new Response(JSON.stringify("too bad"), {
status: 403,
headers: {
"Content-Type": "application/json"
}
})
}
const res = await fetch("https://api.resend.com/emails", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${resendApiKey}`
},
body: JSON.stringify({
from: "Union Ceremony <[email protected]>",
to: [email],
reply_to: "[email protected]",
subject: "Your Turn Is Almost Here - Log Into Union Ceremony",
html: `
<p>
Your contribution slot for the Union Trusted Setup Ceremony is almost here.
</p>
<p>
Your place in queue: <strong>5</strong><br/>
Estimated time until your slot: between <strong>1 hour</strong> and <strong>5 hours</strong>
</p>
<p>
Please go to <strong><a href="https://ceremony.union.build">ceremony.union.build</a></strong>, log in, and follow all steps on the page.<br/>
If you do not follow all steps by the time your contribution slot arrives, <strong>you will lose your slot</strong>.
</p>
`
})
})
const data = await res.json()
return new Response(JSON.stringify(data), {
status: 200,
headers: {
"Content-Type": "application/json"
}
})
}

Deno.serve(handler)

0 comments on commit 5374b3e

Please sign in to comment.