mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-14 12:14:42 +01:00
use runtime config
This commit is contained in:
@@ -7,8 +7,9 @@ const MessageValidator = z.object({
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { message } = await readValidatedBody(event, MessageValidator)
|
||||
const { user } = await requireUserSession(event)
|
||||
const config = useRuntimeConfig(event)
|
||||
|
||||
await sendDiscordWebhookMessage({
|
||||
await sendDiscordWebhookMessage(config, {
|
||||
title: 'New guestbook message ✨',
|
||||
description: `**${user.username}** as signed the book : "*${message}*"`,
|
||||
color: 15893567,
|
||||
|
||||
@@ -7,8 +7,9 @@ const SuggestionValidator = z.object({
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { content } = await readValidatedBody(event, SuggestionValidator)
|
||||
const { user } = await requireUserSession(event)
|
||||
const config = useRuntimeConfig(event)
|
||||
|
||||
await sendDiscordWebhookMessage({
|
||||
await sendDiscordWebhookMessage(config, {
|
||||
title: 'New suggestion ✨',
|
||||
description: `**${user.username}** as requested **${content}** for the talents page.`,
|
||||
color: 15237114,
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
/* eslint-disable node/prefer-global/process */
|
||||
import type { RuntimeConfig } from 'nuxt/schema'
|
||||
|
||||
interface WebhookContent {
|
||||
title: string
|
||||
description: string
|
||||
color: number
|
||||
}
|
||||
|
||||
export async function sendDiscordWebhookMessage(content: WebhookContent) {
|
||||
const id = process.env.NUXT_DISCORD_ID
|
||||
const token = process.env.NUXT_DISCORD_TOKEN
|
||||
await $fetch(`https://discordapp.com/api/webhooks/${id}/${token}`, {
|
||||
export async function sendDiscordWebhookMessage(config: RuntimeConfig, content: WebhookContent) {
|
||||
await $fetch(`https://discordapp.com/api/webhooks/${config.discordId}/${config.discordToken}`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
embeds: [
|
||||
|
||||
Reference in New Issue
Block a user