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) => {
|
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,
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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: [
|
||||||
|
|||||||
Reference in New Issue
Block a user