use runtime config

This commit is contained in:
2024-02-26 15:45:31 +01:00
parent 59c7f52255
commit fe3c6e88dc
3 changed files with 8 additions and 7 deletions

View File

@@ -7,8 +7,9 @@ const MessageValidator = z.object({
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const { message } = await readValidatedBody(event, MessageValidator) const { message } = await readValidatedBody(event, MessageValidator)
const { user } = await requireUserSession(event) const { user } = await requireUserSession(event)
const config = useRuntimeConfig(event)
await sendDiscordWebhookMessage({ await sendDiscordWebhookMessage(config, {
title: 'New guestbook message ✨', title: 'New guestbook message ✨',
description: `**${user.username}** as signed the book : "*${message}*"`, description: `**${user.username}** as signed the book : "*${message}*"`,
color: 15893567, color: 15893567,

View File

@@ -7,8 +7,9 @@ const SuggestionValidator = z.object({
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const { content } = await readValidatedBody(event, SuggestionValidator) const { content } = await readValidatedBody(event, SuggestionValidator)
const { user } = await requireUserSession(event) const { user } = await requireUserSession(event)
const config = useRuntimeConfig(event)
await sendDiscordWebhookMessage({ await sendDiscordWebhookMessage(config, {
title: 'New suggestion ✨', title: 'New suggestion ✨',
description: `**${user.username}** as requested **${content}** for the talents page.`, description: `**${user.username}** as requested **${content}** for the talents page.`,
color: 15237114, color: 15237114,

View File

@@ -1,14 +1,13 @@
/* eslint-disable node/prefer-global/process */ import type { RuntimeConfig } from 'nuxt/schema'
interface WebhookContent { interface WebhookContent {
title: string title: string
description: string description: string
color: number color: number
} }
export async function sendDiscordWebhookMessage(content: WebhookContent) { export async function sendDiscordWebhookMessage(config: RuntimeConfig, content: WebhookContent) {
const id = process.env.NUXT_DISCORD_ID await $fetch(`https://discordapp.com/api/webhooks/${config.discordId}/${config.discordToken}`, {
const token = process.env.NUXT_DISCORD_TOKEN
await $fetch(`https://discordapp.com/api/webhooks/${id}/${token}`, {
method: 'POST', method: 'POST',
body: { body: {
embeds: [ embeds: [