2024-01-25 16:32:45 +00:00
|
|
|
import { fetcher } from 'itty-fetcher'
|
|
|
|
import { FeedbackSchema, getFeedbackOption } from '../types/Feedback'
|
2023-11-12 16:42:57 +00:00
|
|
|
|
|
|
|
export default defineEventHandler(async (event) => {
|
2024-01-25 16:32:45 +00:00
|
|
|
const { message, page, type } = await readValidatedBody(
|
|
|
|
event,
|
|
|
|
FeedbackSchema.parseAsync
|
|
|
|
)
|
|
|
|
const env = useRuntimeConfig(event)
|
2023-11-12 16:42:57 +00:00
|
|
|
|
2024-01-25 16:32:45 +00:00
|
|
|
let description = `${message}\n\n`
|
|
|
|
if (page) description += `**Page:** \`${page}\``
|
2023-11-12 16:42:57 +00:00
|
|
|
|
|
|
|
await fetcher()
|
|
|
|
.post(env.WEBHOOK_URL, {
|
2024-01-25 16:32:45 +00:00
|
|
|
username: 'Feedback',
|
|
|
|
avatar_url:
|
|
|
|
'https://i.kym-cdn.com/entries/icons/facebook/000/043/403/cover3.jpg',
|
2023-11-12 16:42:57 +00:00
|
|
|
embeds: [
|
|
|
|
{
|
|
|
|
color: 3447003,
|
2023-11-19 11:27:54 +00:00
|
|
|
title: getFeedbackOption(type).label,
|
2024-01-25 16:32:45 +00:00
|
|
|
description
|
|
|
|
}
|
|
|
|
]
|
2023-11-12 16:42:57 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-01-25 16:32:45 +00:00
|
|
|
throw new Error(error)
|
|
|
|
})
|
2023-11-12 16:42:57 +00:00
|
|
|
|
2024-01-25 16:32:45 +00:00
|
|
|
return { status: 'ok' }
|
|
|
|
})
|