mirror of
https://github.com/fmhy/edit.git
synced 2025-07-29 23:32:17 +10:00
hello world, again
This commit is contained in:
commit
f479740dd1
133 changed files with 32895 additions and 0 deletions
11
api/middleware/cors.ts
Normal file
11
api/middleware/cors.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { corsEventHandler } from 'nitro-cors'
|
||||
|
||||
export default corsEventHandler(
|
||||
(_event) => {
|
||||
/** no-op */
|
||||
},
|
||||
{
|
||||
origin: '*',
|
||||
methods: '*'
|
||||
}
|
||||
)
|
45
api/routes/feedback.post.ts
Normal file
45
api/routes/feedback.post.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { fetcher } from 'itty-fetcher'
|
||||
import {
|
||||
FeedbackSchema,
|
||||
getFeedbackOption
|
||||
} from '../../docs/.vitepress/types/Feedback'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { message, page, type } = await readValidatedBody(
|
||||
event,
|
||||
FeedbackSchema.parseAsync
|
||||
)
|
||||
const env = useRuntimeConfig(event)
|
||||
|
||||
// FIXME: somehow this is not working, but it worked before
|
||||
// const path = 'feedback'
|
||||
//
|
||||
// const { success } = await env.MY_RATE_LIMITER.limit({ key: path })
|
||||
// if (!success) {
|
||||
// return new Response('429 Failure – global rate limit exceeded', {
|
||||
// status: 429
|
||||
// })
|
||||
// }
|
||||
|
||||
let description = `${message}\n\n`
|
||||
if (page) description += `**Page:** \`${page}\``
|
||||
|
||||
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(type).label,
|
||||
description
|
||||
}
|
||||
]
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
})
|
||||
|
||||
return { status: 'ok' }
|
||||
})
|
3
api/routes/index.ts
Normal file
3
api/routes/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default eventHandler(() => {
|
||||
return { nitro: 'works' }
|
||||
})
|
69
api/routes/single-page.ts
Normal file
69
api/routes/single-page.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import { fetcher } from 'itty-fetcher'
|
||||
|
||||
// Look inside tbe docs directory
|
||||
const GITHUB_REPO = 'https://api.github.com/repos/fmhy/FMHYEdit/contents/docs/'
|
||||
const EXCLUDE_FILES = ['README.md', 'index.md', 'feedback.md', 'posts.md']
|
||||
const EXCLUDE_DIRECTORIES = ['posts/']
|
||||
|
||||
interface File {
|
||||
name: string
|
||||
path: string
|
||||
sha: string
|
||||
size: number
|
||||
url: string
|
||||
html_url: string
|
||||
git_url: string
|
||||
download_url: string | null
|
||||
type: string
|
||||
_links: {
|
||||
self: string
|
||||
git: string
|
||||
html: string
|
||||
}
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
let body = '<!-- This is autogenerated content, do not edit manually. -->\n'
|
||||
const f = fetcher({
|
||||
headers: {
|
||||
'User-Agent': 'taskylizard'
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
// Fetch the list of files in the repository
|
||||
const files = await f.get<File[]>(GITHUB_REPO)
|
||||
|
||||
// Filter out the excluded files and non-markdown files
|
||||
const markdownFiles = files.filter((file: File) => {
|
||||
const isExcludedFile = EXCLUDE_FILES.includes(file.name)
|
||||
const isInExcludedDirectory = EXCLUDE_DIRECTORIES.some((dir) =>
|
||||
file.path.startsWith(dir)
|
||||
)
|
||||
const isMarkdownFile = file.name.endsWith('.md')
|
||||
|
||||
return isMarkdownFile && !isExcludedFile && !isInExcludedDirectory
|
||||
})
|
||||
|
||||
// console.info(markdownFiles.map((f) => f.name))
|
||||
|
||||
// Fetch and concatenate the contents of the markdown files
|
||||
const contents = await Promise.all(
|
||||
markdownFiles.map(async (file: File) => {
|
||||
const content = await f.get<string>(file.download_url)
|
||||
return content
|
||||
})
|
||||
)
|
||||
|
||||
body += contents.join('\n\n')
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 500,
|
||||
body: `Error fetching markdown files: ${error.message}`
|
||||
}
|
||||
}
|
||||
|
||||
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
|
||||
appendResponseHeader(event, 'content-type', 'text/markdown;charset=utf-8')
|
||||
return body
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue