Commit 534f08cff2

534f08cff22c9e3b159ba30e5478e933186d8f7d

parent: 62f467d2e2

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-08-31 05:41 UTC

feedback

Layout: unified · split

api/middleware/cors.ts deleted −13
@@ -1,13 +0,0 @@
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8import { corsEventHandler } from 'nitro-cors'
9
10export default corsEventHandler((_event) => {}, {
11 origin: '*',
12 methods: '*'
13})
api/routes/index.post.ts deleted −68
@@ -1,68 +0,0 @@
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8import { fetcher } from 'itty-fetcher'
9import {
10 FeedbackSchema,
11 getFeedbackOption
12} from '../../docs/.vitepress/types/Feedback'
13
14export default defineEventHandler(async (event) => {
15 const { message, page, type, heading } = await readValidatedBody(
16 event,
17 FeedbackSchema.parseAsync
18 )
19 const env = useRuntimeConfig(event)
20
21 const fields = [
22 {
23 name: 'Page',
24 value: page,
25 inline: true
26 },
27 {
28 name: 'Message',
29 value: message,
30 inline: false
31 }
32 ]
33
34 if (heading) {
35 fields.unshift({
36 name: 'Section',
37 value: heading,
38 inline: true
39 })
40 }
41
42 // FIXME: somehow this is not working, but it worked before
43 // const path = 'feedback'
44 //
45 // const { success } = await env.MY_RATE_LIMITER.limit({ key: path })
46 // if (!success) {
47 // return new Response('429 Failure – global rate limit exceeded', {
48 // status: 429
49 // })
50 // }
51
52 await fetcher()
53 .post(env.WEBHOOK_URL, {
54 username: 'Feedback',
55 embeds: [
56 {
57 color: 3447003,
58 title: getFeedbackOption(type)!.label,
59 fields
60 }
61 ]
62 })
63 .catch((error) => {
64 throw new Error(error)
65 })
66
67 return { status: 'ok' }
68})
api/routes/op.post.ts deleted −36
@@ -1,36 +0,0 @@
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8import { joinURL } from 'ufo'
9
10export default defineEventHandler(async (event) => {
11 const config = useRuntimeConfig(event).op
12
13 try {
14 const target = joinURL(config.url, 'track')
15
16 const headers = {
17 'X-Forwarded-For': getRequestIP(event, { xForwardedFor: true }),
18 'Content-Type': 'application/json',
19 'openpanel-client-id': config.id
20 }
21
22 headers['openpanel-sdk-name'] = 'nitro'
23 headers['openpanel-sdk-version'] = '1.0.0'
24
25 return proxyRequest(event, target, {
26 headers
27 })
28 } catch (error) {
29 console.error(error)
30
31 throw createError({
32 statusCode: 502,
33 message: 'Failed to proxy request'
34 })
35 }
36})
api/routes/single-page.ts deleted −77
@@ -1,77 +0,0 @@
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8import { fetcher } from 'itty-fetcher'
9
10// Look inside tbe docs directory
11const GITHUB_REPO =
12 'https://api.github.com/repos/wotakumoe/wotaku/contents/docs/'
13const EXCLUDE_FILES = ['README.md', 'index.md', 'credits.md', 'faq.md']
14const EXCLUDE_DIRECTORIES = ['glossary/', 'guides/', 'torrenting/']
15
16interface File {
17 name: string
18 path: string
19 sha: string
20 size: number
21 url: string
22 html_url: string
23 git_url: string
24 download_url: string | null
25 type: string
26 _links: {
27 self: string
28 git: string
29 html: string
30 }
31}
32
33export default defineEventHandler(async (event) => {
34 let body = '<!-- This is autogenerated content, do not edit manually. -->\n'
35 const f = fetcher({
36 headers: {
37 'User-Agent': 'taskylizard'
38 }
39 })
40
41 try {
42 // Fetch the list of files in the repository
43 const files = await f.get<File[]>(GITHUB_REPO)
44
45 // Filter out the excluded files and non-markdown files
46 const markdownFiles = files.filter((file: File) => {
47 const isExcludedFile = EXCLUDE_FILES.includes(file.name)
48 const isInExcludedDirectory = EXCLUDE_DIRECTORIES.some((dir) =>
49 file.path.startsWith(dir)
50 )
51 const isMarkdownFile = file.name.endsWith('.md')
52
53 return isMarkdownFile && !isExcludedFile && !isInExcludedDirectory
54 })
55
56 // console.info(markdownFiles.map((f) => f.name))
57
58 // Fetch and concatenate the contents of the markdown files
59 const contents = await Promise.all(
60 markdownFiles.map(async (file: File) => {
61 const content = await f.get<string>(file.download_url)
62 return content
63 })
64 )
65
66 body += contents.join('\n\n')
67 } catch (error) {
68 return {
69 status: 500,
70 body: `Error fetching markdown files: ${error.message}`
71 }
72 }
73
74 // biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
75 appendResponseHeader(event, 'content-type', 'text/markdown;charset=utf-8')
76 return body
77})
api/routes/test.ts deleted −10
@@ -1,10 +0,0 @@
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8export default eventHandler(() => {
9 return { nitro: 'works' }
10})
api/tsconfig.json deleted −3
@@ -1,3 +0,0 @@
1{
2 "extends": "../.nitro/types/tsconfig.json"
3}
docs/.vitepress/theme/components/Feedback.vue +45 −20
@@ -47,40 +47,58 @@ const loading = ref<boolean>(false)
4747const error = ref<unknown>(null)
4848const success = ref<boolean>(false)
4949
50// Generate or retrieve stable visitor ID from localStorage
51function getVisitorId(): string {
52 const key = 'wotaku_visitor_id'
53 let id = localStorage.getItem(key)
54 if (!id || id.length !== 32) {
55 id = crypto.randomUUID().replace(/-/g, '').slice(0, 32)
56 localStorage.setItem(key, id)
57 }
58 return id
59}
60
5061const isDisabled = computed(() => {
5162 return (
52 !feedback.message.length ||
53 feedback.message.length < 5 ||
54 feedback.message.length > 1000
63 !feedback.content.length ||
64 feedback.content.length < 5 ||
65 feedback.content.length > 2000
5566 )
5667})
5768
5869// prettier-ignore
5970const feedback = reactive<
60 Pick<FeedbackType, 'message' | 'page'> & Partial<Pick<FeedbackType, 'type'>>
71 Pick<FeedbackType, 'content' | 'page'> & Partial<Pick<FeedbackType, 'type' | 'name'>>
6172>({
6273 page: getURL(props.heading!),
63 message: ''
74 content: '',
75 name: ''
6476})
6577
6678const selectedOption = ref(feedbackOptions[0])
6779
68async function handleSubmit(type?: FeedbackType['type']) {
69 if (type) {
70 feedback.type = type
71 selectedOption.value = getFeedbackOption(type)!
72 }
80function selectType(type: FeedbackType['type']) {
81 feedback.type = type
82 selectedOption.value = getFeedbackOption(type)!
83 error.value = null
84}
85
86async function handleSubmit() {
7387 loading.value = true
88 success.value = true
89 error.value = null
7490
75 const body: FeedbackType = {
76 message: feedback.message,
91 const body = {
92 content: feedback.content,
7793 type: feedback.type!,
7894 page: feedback.page,
79 ...(props.heading && { heading: props.heading })
95 visitorId: getVisitorId(),
96 ...(props.heading && { heading: props.heading }),
97 ...(feedback.name && { name: feedback.name })
8098 }
8199
82100 try {
83 const response = await fetch('https://wotaku.tasky.workers.dev', {
101 const response = await fetch('https://wotaku-feedback.duckling.workers.dev/api/feedback', {
84102 method: 'POST',
85103 headers: {
86104 'Content-Type': 'application/json'
@@ -90,13 +108,11 @@ async function handleSubmit(type?: FeedbackType['type']) {
90108
91109 const data = await response.json()
92110 if (data.error) {
111 success.value = false
93112 error.value = data.error
94 return
95 }
96 if (data.status === 'ok') {
97 success.value = true
98113 }
99114 } catch (err) {
115 success.value = false
100116 error.value = err
101117 } finally {
102118 loading.value = false
@@ -152,7 +168,7 @@ const toggleCard = () => (isCardShown.value = !isCardShown.value)
152168 v-for="item in feedbackOptions"
153169 :key="item.value"
154170 class="bg-bg border-$vp-c-default-soft hover:border-primary mt-2 select-none rounded border-2 border-solid font-bold transition-all duration-250 rounded-lg text-[14px] font-500 leading-normal m-0 px-3 py-1.5 text-center align-middle whitespace-nowrap"
155 @click="handleSubmit(item.value)"
171 @click="selectType(item.value)"
156172 >
157173 <span :class="[item.icon, 'mr-1 inline-block align-middle']" />
158174 <span class="align-middle">{{ item.label }}</span>
@@ -244,11 +260,20 @@ const toggleCard = () => (isCardShown.value = !isCardShown.value)
244260 </details>
245261 </div>
246262 <textarea
247 v-model="feedback.message"
263 v-model="feedback.content"
248264 autofocus
249265 class="feedback-textarea bg-$vp-c-bg-alt text-$vp-c-text-2 w-full h-[100px] border border-$vp-c-divider rounded px-3 py-1.5 border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 border-2 border-solid"
250266 :placeholder="prompt"
251267 />
268 <input
269 v-model="feedback.name"
270 maxlength="50"
271 class="bg-$vp-c-bg-alt text-$vp-c-text-2 w-full border border-$vp-c-divider rounded px-3 py-1.5 mt-2 b-rd-4 border-2 border-solid text-sm"
272 placeholder="Name (optional)"
273 />
274 <p v-if="error" class="text-red-400 text-sm mt-1">
275 Failed to send: {{ String(error) }}
276 </p>
252277 <p class="desc mb-2">
253278 If you want a reply to your feedback, feel free to mention a contact
254279 in the message or join our
docs/.vitepress/types/Feedback.ts +4 −3
@@ -8,7 +8,7 @@
88import z from 'zod'
99
1010export const FeedbackSchema = z.object({
11 message: z.string().min(5).max(1000),
11 content: z.string().min(5).max(2000),
1212 type: z.enum([
1313 'submit',
1414 'update',
@@ -18,8 +18,9 @@ export const FeedbackSchema = z.object({
1818 'other'
1919 ]),
2020 page: z.string().url(),
21 // For heading based feedback
22 heading: z.string().min(3).max(20).optional()
21 heading: z.string().min(3).max(50).optional(),
22 name: z.string().min(1).max(50).optional(),
23 visitorId: z.string().length(32)
2324})
2425
2526export interface Option {
nitro.config.ts deleted −21
@@ -1,21 +0,0 @@
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8// https://nitro.unjs.io/config
9export default defineNitroConfig({
10 compatibilityDate: '2024-12-16',
11 runtimeConfig: {
12 WEBHOOK_URL: process.env.WEBHOOK_URL,
13 op: { url: process.env.OP_URL, id: process.env.OP_ID }
14 },
15 srcDir: 'api',
16 routeRules: {
17 '/': {
18 cors: false
19 }
20 }
21})
package.json +1 −8
@@ -6,11 +6,7 @@
66 "format": "dprint fmt",
77 "docs:dev": "vitepress dev docs",
88 "docs:build": "NODE_OPTIONS='--max-old-space-size=8192' vitepress build docs",
9 "docs:preview": "vitepress preview docs",
10 "api:prepare": "nitropack prepare",
11 "api:dev": "nitropack dev",
12 "api:build": "nitropack build",
13 "api:preview": "node .output/server/index.mjs"
9 "docs:preview": "vitepress preview docs"
1410 },
1511 "dependencies": {
1612 "@fmhy/components": "^0.0.3",
@@ -27,7 +23,6 @@
2723 "dprint": "^0.50.2",
2824 "floating-vue": "^5.2.2",
2925 "gray-matter": "^4.0.3",
30 "itty-fetcher": "^1.0.10",
3126 "lucide-vue-next": "^0.553.0",
3227 "mark.js": "^8.11.1",
3328 "markdown-it": "^14.1.0",
@@ -37,8 +32,6 @@
3732 "medium-zoom": "^1.1.0",
3833 "minisearch": "^7.2.0",
3934 "motion-v": "^1.7.4",
40 "nitro-cors": "^0.7.1",
41 "nitropack": "^2.10.4",
4235 "oxc-minify": "^0.96.0",
4336 "pathe": "^2.0.3",
4437 "react": "^19.2.6",
wrangler.toml deleted −5
@@ -1,5 +0,0 @@
1name = "wotaku"
2main = ".output/server/index.mjs"
3workers_dev = true
4account_id = "fe5d9bd14160b07939282e45f63eb5ad"
5compatibility_date = "2022-09-10"