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