diff --git a/.vitepress/routes/index.post.ts b/.vitepress/routes/index.post.ts index 979fd8ac6..27515c312 100644 --- a/.vitepress/routes/index.post.ts +++ b/.vitepress/routes/index.post.ts @@ -1,10 +1,5 @@ import { fetcher } from "itty-fetcher"; - -interface Feedback { - message: string; - feedbackType?: string; - contactEmail?: string; -} +import { FeedbackSchema } from "../types/Feedback"; const feedbackOptions = [ { label: "🐞 Bug", value: "bug" }, @@ -24,12 +19,15 @@ function getFeedbackOption(value: string) { } export default defineEventHandler(async (event) => { - const { message, contactEmail, feedbackType } = await readBody(event); + const { message, page, contact, type } = await readValidatedBody(event, FeedbackSchema.parse); const env = useRuntimeConfig(event); - if (!["bug", "suggestion", "other", "appreciate"].includes(feedbackType!) || !message) { + if (!["bug", "suggestion", "other", "appreciate"].includes(type!) || !message) throw new Error("Invalid input."); - } + + let description = `${message}\n\n`; + if (contact) description += `**Contact:** ${contact}`; + if (page) description += `**Page:** \`${page}\``; await fetcher() .post(env.WEBHOOK_URL, { @@ -38,8 +36,8 @@ export default defineEventHandler(async (event) => { embeds: [ { color: 3447003, - title: getFeedbackOption(feedbackType).label, - description: contactEmail ? `${message}\n\n**Contact:** ${contactEmail}` : message, + title: getFeedbackOption(type).label, + description: description, }, ], }) @@ -47,5 +45,5 @@ export default defineEventHandler(async (event) => { throw new Error(error); }); - return { status: "success" }; + return { status: "ok" }; }); diff --git a/.vitepress/theme/components/Feedback.vue b/.vitepress/theme/components/Feedback.vue index 91fb4c175..b0a2e5f95 100644 --- a/.vitepress/theme/components/Feedback.vue +++ b/.vitepress/theme/components/Feedback.vue @@ -1,18 +1,14 @@