From b9bebb6c8411048d742b08c0db163d3da30a4342 Mon Sep 17 00:00:00 2001 From: taskylizard <75871323+taskylizard@users.noreply.github.com> Date: Sat, 4 Nov 2023 20:24:25 +0530 Subject: [PATCH] Add feedback API --- .github/assets/README.md | 24 - .github/workflows/deploy-api.yml | 39 + .gitignore | 6 + .npmrc | 2 + .vitepress/routes/index.post.ts | 51 + .vitepress/routes/test.ts | 3 + .vitepress/theme/components/Feedback.vue | 24 +- .vitepress/theme/components/SidebarCard.vue | 10 +- nitro.config.ts | 10 + package.json | 7 +- pnpm-lock.yaml | 1962 ++++++++++++++++++- tsconfig.json | 19 +- wrangler.toml | 4 + 13 files changed, 2051 insertions(+), 110 deletions(-) delete mode 100644 .github/assets/README.md create mode 100644 .github/workflows/deploy-api.yml create mode 100644 .npmrc create mode 100644 .vitepress/routes/index.post.ts create mode 100644 .vitepress/routes/test.ts create mode 100644 nitro.config.ts create mode 100644 wrangler.toml diff --git a/.github/assets/README.md b/.github/assets/README.md deleted file mode 100644 index e50963aa5..000000000 --- a/.github/assets/README.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -image: /static/banner4.png -icon: ":wave:" ---- -# Welcome - -![](/static/banner4.png) - -**The Largest Collection of Free Stuff On The Internet!** - -* Anyone can suggest [changes or corrections](https://rentry.org/fmhyedit) to the wiki. -* If you're adding a new site, please [search](https://raw.githubusercontent.com/nbats/FMHYedit/main/single-page) first to make sure we don't already have it. -* Approved edits will be applied to this site and all [🔒 backups](https://www.reddit.com/r/FREEMEDIAHECKYEAH/wiki/backups). -* You can send us stuff directly via [💬 Discord](https://redd.it/17f8msf). -* You can discuss the wiki or anything you'd like on our [🐭 Lemmy](https://lemmy.dbzer0.com/c/freemediaheckyeah). -* You can also checkout our subreddit, [r/FREEMEDIAHECKYEAH](https://www.reddit.com/r/FREEMEDIAHECKYEAH/) to know about any major updates to the wiki. - -*** - -Emoji Legend: - -* 🌐 - 3rd Party Indexes -* ↪️ - Storage Page Links -* ⭐ - Community Recommendations diff --git a/.github/workflows/deploy-api.yml b/.github/workflows/deploy-api.yml new file mode 100644 index 000000000..f6b7e0bf0 --- /dev/null +++ b/.github/workflows/deploy-api.yml @@ -0,0 +1,39 @@ +name: Deploy API + +on: + push: + branches: + - main + - vitepress + pull_request: + branches: + - main + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +jobs: + ci: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 6 + - uses: pnpm/action-setup@v2.4.0 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'pnpm' + + - run: pnpm install --no-frozen-lockfile + + - name: Build + run: pnpm api:build + env: + NITRO_PRESET: cloudflare + + - name: Publish to Cloudflare + uses: cloudflare/wrangler-action@3 + with: + apiToken: ${{ secrets.CF_API_TOKEN }} diff --git a/.gitignore b/.gitignore index 6d8a3f476..b94471b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ **/.vitepress/dist **/.vitepress/cache node_modules +*.log* +.nitro +.cache +.output +.env +dist diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..cf0404245 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +shamefully-hoist=true +strict-peer-dependencies=false diff --git a/.vitepress/routes/index.post.ts b/.vitepress/routes/index.post.ts new file mode 100644 index 000000000..493a16037 --- /dev/null +++ b/.vitepress/routes/index.post.ts @@ -0,0 +1,51 @@ +import { fetcher } from "itty-fetcher"; + +interface Feedback { + message: string; + feedbackType?: string; + contactEmail?: string; +} + +const feedbackOptions = [ + { label: "🐞 Bug", value: "bug" }, + { + label: "♻️ Suggestion", + value: "suggestion", + }, + { label: "📂 Other", value: "other" }, + { + label: "❤️ Appreciation", + value: "appreciate", + }, +]; + +function getFeedbackOption(value: string) { + return feedbackOptions.find((option) => option.value === value); +} + +export default defineEventHandler(async (event) => { + const { message, contactEmail, feedbackType } = await readBody(event); + const env = useRuntimeConfig(event); + + if (!["bug", "suggestion", "other", "appreciate"].includes(feedbackType!) || !message) { + throw new Error("Invalid input."); + } + + 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, + title: getFeedbackOption(feedbackType).label, + description: contactEmail ? `${message}\n\n**Contact:** ${contactEmail}` : message, + }, + ], + }) + .catch(({ status, error }) => { + throw new Error(`Error code ${status}: ${error}`); + }); + + return "success"; +}); diff --git a/.vitepress/routes/test.ts b/.vitepress/routes/test.ts new file mode 100644 index 000000000..a6fcdc197 --- /dev/null +++ b/.vitepress/routes/test.ts @@ -0,0 +1,3 @@ +export default eventHandler(() => { + return { nitro: "works" }; +}); diff --git a/.vitepress/theme/components/Feedback.vue b/.vitepress/theme/components/Feedback.vue index 9ef84adeb..dcb8b14c4 100644 --- a/.vitepress/theme/components/Feedback.vue +++ b/.vitepress/theme/components/Feedback.vue @@ -43,7 +43,7 @@ async function handleSubmit(type?: string) { }; try { - const response = await fetch("https://fmhy.tk/api/feedback", { + const response = await fetch("https://feedback.tasky.workers.dev", { method: "POST", headers: { "Content-Type": "application/json", @@ -76,11 +76,7 @@ async function handleSubmit(type?: string) {
-
@@ -90,15 +86,14 @@ async function handleSubmit(type?: string) {

The wiki is...

{{ getFeedbackOption(feedback.feedbackType)?.label }} -