Commit 534f08cff2
Unsigned
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 | */ | |
| 8 | import { corsEventHandler } from 'nitro-cors' | |
| 9 | ||
| 10 | export 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 | */ | |
| 8 | import { fetcher } from 'itty-fetcher' | |
| 9 | import { | |
| 10 | FeedbackSchema, | |
| 11 | getFeedbackOption | |
| 12 | } from '../../docs/.vitepress/types/Feedback' | |
| 13 | ||
| 14 | export 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 | */ | |
| 8 | import { joinURL } from 'ufo' | |
| 9 | ||
| 10 | export 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 | */ | |
| 8 | import { fetcher } from 'itty-fetcher' | |
| 9 | ||
| 10 | // Look inside tbe docs directory | |
| 11 | const GITHUB_REPO = | |
| 12 | 'https://api.github.com/repos/wotakumoe/wotaku/contents/docs/' | |
| 13 | const EXCLUDE_FILES = ['README.md', 'index.md', 'credits.md', 'faq.md'] | |
| 14 | const EXCLUDE_DIRECTORIES = ['glossary/', 'guides/', 'torrenting/'] | |
| 15 | ||
| 16 | interface 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 | ||
| 33 | export 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 | */ | |
| 8 | export 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) | ||
| 47 | 47 | const error = ref<unknown>(null) |
| 48 | 48 | const success = ref<boolean>(false) |
| 49 | 49 | |
| 50 | // Generate or retrieve stable visitor ID from localStorage | |
| 51 | function 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 | ||
| 50 | 61 | const isDisabled = computed(() => { |
| 51 | 62 | 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 | |
| 55 | 66 | ) |
| 56 | 67 | }) |
| 57 | 68 | |
| 58 | 69 | // prettier-ignore |
| 59 | 70 | const feedback = reactive< |
| 60 | Pick<FeedbackType, 'message' | 'page'> & Partial<Pick<FeedbackType, 'type'>> | |
| 71 | Pick<FeedbackType, 'content' | 'page'> & Partial<Pick<FeedbackType, 'type' | 'name'>> | |
| 61 | 72 | >({ |
| 62 | 73 | page: getURL(props.heading!), |
| 63 | message: '' | |
| 74 | content: '', | |
| 75 | name: '' | |
| 64 | 76 | }) |
| 65 | 77 | |
| 66 | 78 | const selectedOption = ref(feedbackOptions[0]) |
| 67 | 79 | |
| 68 | async function handleSubmit(type?: FeedbackType['type']) { | |
| 69 | if (type) { | |
| 70 | feedback.type = type | |
| 71 | selectedOption.value = getFeedbackOption(type)! | |
| 72 | } | |
| 80 | function selectType(type: FeedbackType['type']) { | |
| 81 | feedback.type = type | |
| 82 | selectedOption.value = getFeedbackOption(type)! | |
| 83 | error.value = null | |
| 84 | } | |
| 85 | ||
| 86 | async function handleSubmit() { | |
| 73 | 87 | loading.value = true |
| 88 | success.value = true | |
| 89 | error.value = null | |
| 74 | 90 | |
| 75 | const body: FeedbackType = { | |
| 76 | message: feedback.message, | |
| 91 | const body = { | |
| 92 | content: feedback.content, | |
| 77 | 93 | type: feedback.type!, |
| 78 | 94 | page: feedback.page, |
| 79 | ...(props.heading && { heading: props.heading }) | |
| 95 | visitorId: getVisitorId(), | |
| 96 | ...(props.heading && { heading: props.heading }), | |
| 97 | ...(feedback.name && { name: feedback.name }) | |
| 80 | 98 | } |
| 81 | 99 | |
| 82 | 100 | try { |
| 83 | const response = await fetch('https://wotaku.tasky.workers.dev', { | |
| 101 | const response = await fetch('https://wotaku-feedback.duckling.workers.dev/api/feedback', { | |
| 84 | 102 | method: 'POST', |
| 85 | 103 | headers: { |
| 86 | 104 | 'Content-Type': 'application/json' |
| @@ -90,13 +108,11 @@ async function handleSubmit(type?: FeedbackType['type']) { | ||
| 90 | 108 | |
| 91 | 109 | const data = await response.json() |
| 92 | 110 | if (data.error) { |
| 111 | success.value = false | |
| 93 | 112 | error.value = data.error |
| 94 | return | |
| 95 | } | |
| 96 | if (data.status === 'ok') { | |
| 97 | success.value = true | |
| 98 | 113 | } |
| 99 | 114 | } catch (err) { |
| 115 | success.value = false | |
| 100 | 116 | error.value = err |
| 101 | 117 | } finally { |
| 102 | 118 | loading.value = false |
| @@ -152,7 +168,7 @@ const toggleCard = () => (isCardShown.value = !isCardShown.value) | ||
| 152 | 168 | v-for="item in feedbackOptions" |
| 153 | 169 | :key="item.value" |
| 154 | 170 | 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)" | |
| 156 | 172 | > |
| 157 | 173 | <span :class="[item.icon, 'mr-1 inline-block align-middle']" /> |
| 158 | 174 | <span class="align-middle">{{ item.label }}</span> |
| @@ -244,11 +260,20 @@ const toggleCard = () => (isCardShown.value = !isCardShown.value) | ||
| 244 | 260 | </details> |
| 245 | 261 | </div> |
| 246 | 262 | <textarea |
| 247 | v-model="feedback.message" | |
| 263 | v-model="feedback.content" | |
| 248 | 264 | autofocus |
| 249 | 265 | 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" |
| 250 | 266 | :placeholder="prompt" |
| 251 | 267 | /> |
| 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> | |
| 252 | 277 | <p class="desc mb-2"> |
| 253 | 278 | If you want a reply to your feedback, feel free to mention a contact |
| 254 | 279 | in the message or join our |
docs/.vitepress/types/Feedback.ts +4 −3
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | import z from 'zod' |
| 9 | 9 | |
| 10 | 10 | export const FeedbackSchema = z.object({ |
| 11 | message: z.string().min(5).max(1000), | |
| 11 | content: z.string().min(5).max(2000), | |
| 12 | 12 | type: z.enum([ |
| 13 | 13 | 'submit', |
| 14 | 14 | 'update', |
| @@ -18,8 +18,9 @@ export const FeedbackSchema = z.object({ | ||
| 18 | 18 | 'other' |
| 19 | 19 | ]), |
| 20 | 20 | 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) | |
| 23 | 24 | }) |
| 24 | 25 | |
| 25 | 26 | export 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 | |
| 9 | export 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 @@ | ||
| 6 | 6 | "format": "dprint fmt", |
| 7 | 7 | "docs:dev": "vitepress dev docs", |
| 8 | 8 | "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" | |
| 14 | 10 | }, |
| 15 | 11 | "dependencies": { |
| 16 | 12 | "@fmhy/components": "^0.0.3", |
| @@ -27,7 +23,6 @@ | ||
| 27 | 23 | "dprint": "^0.50.2", |
| 28 | 24 | "floating-vue": "^5.2.2", |
| 29 | 25 | "gray-matter": "^4.0.3", |
| 30 | "itty-fetcher": "^1.0.10", | |
| 31 | 26 | "lucide-vue-next": "^0.553.0", |
| 32 | 27 | "mark.js": "^8.11.1", |
| 33 | 28 | "markdown-it": "^14.1.0", |
| @@ -37,8 +32,6 @@ | ||
| 37 | 32 | "medium-zoom": "^1.1.0", |
| 38 | 33 | "minisearch": "^7.2.0", |
| 39 | 34 | "motion-v": "^1.7.4", |
| 40 | "nitro-cors": "^0.7.1", | |
| 41 | "nitropack": "^2.10.4", | |
| 42 | 35 | "oxc-minify": "^0.96.0", |
| 43 | 36 | "pathe": "^2.0.3", |
| 44 | 37 | "react": "^19.2.6", |
wrangler.toml deleted −5
| @@ -1,5 +0,0 @@ | ||
| 1 | name = "wotaku" | |
| 2 | main = ".output/server/index.mjs" | |
| 3 | workers_dev = true | |
| 4 | account_id = "fe5d9bd14160b07939282e45f63eb5ad" | |
| 5 | compatibility_date = "2022-09-10" | |