mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 14:30:22 +00:00
* feat: support webhook * feat: bot webhook * types: add enums for webhook * feat: update webhook status by param * feat: send webhook of server count change * feat: send webhook of vote * chore: add desc of faulty webhook * chore: set initial value * feat: add collection of clients * chore: simplify * feat: set webhook status dynamically * feat: webhook for discord * refactor: rename WebhookStatus.Paused * refactor: make webhookClients to one object * feat: webhook with fetch * feat: add warning prop to input component * feat: display red when warning * feat: check server count properly * feat: handle status codes * refactor: remove double fetch * chore: typo * feat: send failed message * fix: missing id on query * feat: limit response body * feat: use severlist bot to dm * feat: webhook for servers * feat: use env for ids * refactor: remove variables * fix: send discord log * fix: message * feat: include koreanbots in footer * fix: typo * refactor: export function as non default * feat: add verification * feat: add columns * feat: verify bot webhook * feat: verify server webhook * chore: rename key to secret * fix: stringify * chore: remove webhook related columns * refactor: use separate object for webhook * type: add webhook prop to bot / server * fix: implement webhook status * refactor: rename webhook to webhookURL * feat: select webhook props * feat: remove bot's private props * feat: remove server private fields * chore: use makeURLs * type: fix faildSince is type as string * refactor: rename to updateWebhook * chore: make props optional * feat: failedSince * feat: remove failedSince when success * fix: missing import * fix: typo * fix: convert missing prop * fix: typo * chore: remove unnecessary select * fix: missing systax * feat: sort docs * feat: use relay * fix: check status properly * chore: handle relay server error * remove awaits * fix: add base url * fix: typo * chore: remove red highlights * chore: change emoji --------- Co-authored-by: SKINMAKER <skinmaker@SKINMAKERs-iMac.local> Co-authored-by: skinmaker1345 <me@skinmaker.dev>
99 lines
2.7 KiB
TypeScript
99 lines
2.7 KiB
TypeScript
import { NextPage } from 'next'
|
|
import { useEffect, useState } from 'react'
|
|
import { useRouter } from 'next/router'
|
|
import dynamic from 'next/dynamic'
|
|
import { lstat, readdir, readFile } from 'fs/promises'
|
|
import { join } from 'path'
|
|
|
|
import { DocsData } from '@types'
|
|
|
|
import NotFound from 'pages/404'
|
|
import Message from '@components/Message'
|
|
|
|
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
|
const Markdown = dynamic(() => import ('@components/Markdown'))
|
|
|
|
const docsDir = './api-docs/docs'
|
|
const Docs: NextPage<DocsProps> = ({ docs }) => {
|
|
const router = useRouter()
|
|
const [ document, setDoc ] = useState<DocsData>(null)
|
|
useEffect(() => {
|
|
if(!router.query.first) return
|
|
let res = docs?.find(el => el.name === router.query.first)
|
|
if(router.query.second) res = res?.list?.find(el => el.name === router.query.second)
|
|
setDoc(res || { name: 'Not Found' })
|
|
setTimeout(highlightBlocks, 100)
|
|
}, [docs, router.query])
|
|
|
|
useEffect(() => highlightBlocks, [document])
|
|
if(document?.name === 'Not Found') return <NotFound />
|
|
return <DeveloperLayout enabled='docs' docs={docs} currentDoc={(router.query.second || router.query.first) as string}>
|
|
<div className='px-2'>
|
|
{
|
|
!document ? ''
|
|
: <Markdown text={document.text} options={{ openLinksInNewWindow: false }} components={{ message: Message, code }} allowedTag={['message']} />
|
|
}
|
|
</div>
|
|
</DeveloperLayout>
|
|
}
|
|
|
|
export async function getStaticPaths () {
|
|
return {
|
|
paths: [],
|
|
fallback: true
|
|
}
|
|
}
|
|
|
|
export async function getStaticProps () {
|
|
const docs = (await Promise.all((await readdir(docsDir)).map(async el => {
|
|
const isDir = (await lstat(join(docsDir, el))).isDirectory()
|
|
if(!isDir) {
|
|
return {
|
|
name: el.split('.').slice(0, -1).join('.'),
|
|
text: (await readFile(join(docsDir, el))).toString()
|
|
}
|
|
}
|
|
else {
|
|
return {
|
|
name: el,
|
|
list: await Promise.all((await readdir(join(docsDir, el))).map(async e => {
|
|
return {
|
|
name: e.split('.').slice(0, -1).join('.'),
|
|
text: (await readFile(join(docsDir, el, e))).toString()
|
|
}
|
|
}))
|
|
}
|
|
}
|
|
}))).sort((a, b) => {
|
|
if('list' in b && 'text' in a) return -1
|
|
return a.name.localeCompare(b.name)
|
|
})
|
|
|
|
return {
|
|
props: { docs }
|
|
}
|
|
}
|
|
|
|
function code({ children }:{ children: string }):JSX.Element {
|
|
const methods = {
|
|
get: 'text-green-400',
|
|
post: 'text-yellow-400',
|
|
put: 'text-blue-500',
|
|
patch: 'text-yellow-400',
|
|
delete: 'text-red-500'
|
|
}
|
|
return <code className={`${methods[String(children).toLowerCase()]}`}>
|
|
{children}
|
|
</code>
|
|
}
|
|
function highlightBlocks() {
|
|
const nodes = window.document.querySelectorAll('pre code')
|
|
nodes.forEach(el => {
|
|
window.hljs.highlightBlock(el)
|
|
})
|
|
}
|
|
interface DocsProps {
|
|
docs: DocsData[]
|
|
}
|
|
|
|
export default Docs |