mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Compare commits
4 commits
4cafc41b88
...
6e0204bc49
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e0204bc49 | |||
| 0c98097abc | |||
| 24fb8f2b7d | |||
| 210118bf4d |
2 changed files with 17 additions and 4 deletions
|
|
@ -73,5 +73,7 @@
|
|||
"alreadyDonator": "You are already a donator!",
|
||||
"discordNeeded": "You need to link your Discord account to access this page",
|
||||
"discordRoleNeeded": "You need the Donator Discord role to access this page",
|
||||
"addedDonator": "Added donator benefits to your account!"
|
||||
"addedDonator": "Added donator benefits to your account!",
|
||||
"errorDonatorCheck": "Something went wrong when checking your Discord donator status. Please try again later. {error}",
|
||||
"discordRateLimit": "{message} Retry after {retry_after} seconds."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
---
|
||||
import * as m from 'paraglide/messages'
|
||||
import { DISCORD_DONATOR_ID } from 'astro:env/server'
|
||||
import { DISCORD_DONATOR_ID, DISCORD_GUILD_ID } from 'astro:env/server'
|
||||
import prismaClient from 'utils/prisma-client'
|
||||
|
||||
import BaseLayout from 'layouts/base.astro'
|
||||
|
||||
const { session, user, roles } = Astro.locals
|
||||
|
||||
async function getMessage() {
|
||||
|
|
@ -22,13 +24,20 @@ async function getMessage() {
|
|||
return m.discordNeeded()
|
||||
}
|
||||
|
||||
const memberInfoRes = await fetch(`https://discord.com/api/users/@me/guilds/535484312124915714/member`, {
|
||||
const memberInfoRes = await fetch(`https://discord.com/api/users/@me/guilds/${DISCORD_GUILD_ID}/member`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${discordAcc.accessToken}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
})
|
||||
|
||||
if (memberInfoRes.status == 429) {
|
||||
const { message, retry_after }: { message: string; retry_after: number } = await memberInfoRes.json()
|
||||
return m.discordRateLimit({ message, retry_after })
|
||||
} else if (memberInfoRes.status != 200) {
|
||||
return m.errorDonatorCheck({ error: await memberInfoRes.json() })
|
||||
}
|
||||
|
||||
const memberInfo: { roles: string[] } = await memberInfoRes.json()
|
||||
const isDiscordDonator = memberInfo.roles.includes(DISCORD_DONATOR_ID)
|
||||
|
||||
|
|
@ -43,4 +52,6 @@ async function getMessage() {
|
|||
const message = await getMessage()
|
||||
---
|
||||
|
||||
<div>{message}</div>
|
||||
<BaseLayout>
|
||||
<div class='justify-center py-4 flex w-full'>{message}</div>
|
||||
</BaseLayout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue