Add feedback API

This commit is contained in:
taskylizard 2023-11-04 20:24:25 +05:30
parent bf504e0b26
commit b9bebb6c84
No known key found for this signature in database
GPG Key ID: 5CABA3D642DDC497
13 changed files with 2051 additions and 110 deletions

View File

@ -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

39
.github/workflows/deploy-api.yml vendored Normal file
View File

@ -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 }}

6
.gitignore vendored
View File

@ -1,3 +1,9 @@
**/.vitepress/dist
**/.vitepress/cache
node_modules
*.log*
.nitro
.cache
.output
.env
dist

2
.npmrc Normal file
View File

@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false

View File

@ -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<Feedback>(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";
});

View File

@ -0,0 +1,3 @@
export default eventHandler(() => {
return { nitro: "works" };
});

View File

@ -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) {
</div>
</div>
<div class="button-container">
<button
v-for="item in feedbackOptions"
:key="item.value"
class="btn"
@click="handleSubmit(item.value)">
<button v-for="item in feedbackOptions" :key="item.value" class="btn" @click="handleSubmit(item.value)">
<span>{{ item.label }}</span>
</button>
</div>
@ -90,15 +86,14 @@ async function handleSubmit(type?: string) {
<p class="desc">The wiki is...</p>
<div>
<span>{{ getFeedbackOption(feedback.feedbackType)?.label }}</span>
<button
style="margin-left: 0.5rem"
class="btn"
@click="feedback.feedbackType = undefined">
<button style="margin-left: 0.5rem" class="btn" @click="feedback.feedbackType = undefined">
<span class="i-carbon-close-large">close</span>
</button>
</div>
</div>
<textarea v-model="feedback.message" autofocus class="input" />
<p class="desc">Contact, so we can get back to you. (Optional)</p>
<textarea v-model="feedback.contactEmail" class="contact-input" />
<button class="btn btn-primary" :disabled="!feedback.message" @click="handleSubmit()">
Submit
</button>
@ -111,7 +106,7 @@ async function handleSubmit(type?: string) {
</template>
<style scoped>
.step > * + * {
.step>*+* {
margin-top: 1rem;
}
@ -178,6 +173,13 @@ async function handleSubmit(type?: string) {
padding: 0.375rem 0.75rem;
}
.contact-input {
height: 50px;
border: 1px solid #ccc;
border-radius: 4px;
padding: 0.375rem 0.75rem;
}
.desc {
display: block;
line-height: 20px;

View File

@ -20,11 +20,11 @@ import InputField from "./InputField.vue";
<Modal />
</template>
</InputField>
<InputField id="toggle-starred" label="Toggle Starred">
<template #display>
<button class="p-[4px 8px] text-xl i-carbon:star"></button>
</template>
</InputField>
<!-- <InputField id="toggle-starred" label="Toggle Starred"> -->
<!-- <template #display> -->
<!-- <button class="p-[4px 8px] text-xl i-carbon:star"></button> -->
<!-- </template> -->
<!-- </InputField> -->
</div>
</template>

10
nitro.config.ts Normal file
View File

@ -0,0 +1,10 @@
//https://nitro.unjs.io/config
export default defineNitroConfig({
runtimeConfig: {
WEBHOOK_URL: process.env.WEBHOOK_URL,
},
srcDir: ".vitepress",
routeRules: {
"/*": { cors: false },
},
});

View File

@ -5,11 +5,16 @@
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview",
"api:prepare": "nitropack prepare",
"api:dev": "nitropack dev",
"api:build": "nitropack build",
"api:preview": "node .output/server/index.mjs",
"format": "prettier -w --cache ."
},
"dependencies": {
"@headlessui/vue": "^1.7.16",
"fast-glob": "^3.3.1",
"itty-fetcher": "^0.9.4",
"nitropack": "latest",
"pathe": "^1.1.1",
"unocss": "^0.57.1",
"vitepress": "1.0.0-rc.24",

1962
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,3 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "esnext",
"target": "esnext",
"lib": ["DOM", "ESNext"],
"strict": true,
"jsx": "preserve",
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"types": ["vite/client", "vite-plugin-pwa/vanillajs", "vitepress", "./.vitepress/vue-shim.d.ts"]
},
"include": ["./*.ts", "./.vitepress/**/*.ts"],
"exclude": ["dist", "node_modules"]
"extends": "./.nitro/types/tsconfig.json"
}

4
wrangler.toml Normal file
View File

@ -0,0 +1,4 @@
name = "feedback"
main = ".output/server/index.mjs"
workers_dev = true
compatibility_date = "2022-09-10"