feat: added applications route

This commit is contained in:
Junseo Park 2021-02-27 11:01:38 +09:00
parent d3a7dab240
commit 323e9e88a2
5 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,19 @@
import Link from 'next/link'
import DiscordAvatar from './DiscordAvatar'
const Application = ({ type, id, name }:ApplicationProps):JSX.Element => {
return <Link href={`/developers/applications/${type+'s'}/${id}`}>
<div className='relative py-4 px-2 bg-little-white dark:bg-discord-black text-center transform hover:-translate-y-1 transition duration-100 ease-in cursor-pointer rounded-lg'>
<DiscordAvatar userID={id} className='w-full rounded-lg px-2' />
<h2 className='text-xl font-bold pt-2'>{name.slice(0, 7)}{name.length > 7 && '...'}</h2>
</div>
</Link>
}
interface ApplicationProps {
type: 'bot'
id: string
name: string
}
export default Application

View File

@ -0,0 +1,38 @@
import { NextPage, NextPageContext } from 'next'
import dynamic from 'next/dynamic'
import { get } from '@utils/Query'
import { parseCookie } from '@utils/Tools'
import { Bot, User } from '@types'
const Application = dynamic(() => import('@components/Application'))
const Container = dynamic(() => import('@components/Container'))
const SEO = dynamic(() => import('@components/SEO'))
const Applications: NextPage<ApplicationsProps> = ({ user }) => {
return <Container paddingTop>
<SEO title='개발자' description='한국 디스코드봇 리스트 API를 활용하여 봇에 다양한 기능을 추가해보세요.' />
<h1 className='text-3xl font-bold'> </h1>
<p className='text-gray-400'> API를 .</p>
<div className='grid grid-cols-8 gap-4 mt-10'>
{
(user.bots as Bot[]).map(bot => <Application key={bot.id} id={bot.id} name={bot.name} type='bot' />)
}
</div>
</Container>
}
interface ApplicationsProps {
user: User
}
export const getServerSideProps = async (ctx: NextPageContext) => {
const parsed = parseCookie(ctx.req)
const user = await get.Authorization(parsed?.token) || ''
return {
props: { user: await get.user.load(user) }
}
}
export default Applications

View File

@ -0,0 +1,10 @@
import { NextPage } from 'next'
import { useRouter } from 'next/router'
const Developers: NextPage = () => {
const router = useRouter()
router.push('/developers/applications')
return <></>
}
export default Developers

View File

@ -36,6 +36,12 @@ export interface User {
bots: Bot[] | string[]
}
export interface BotSpec {
id: string
webhook: string | null
token: string
}
export enum UserFlags {
general = 0 << 0,
staff = 1 << 0,

View File

@ -47,7 +47,7 @@ async function getBot(id: string, owners=true):Promise<Bot> {
const discordBot = await get.discord.user.load(res[0].id)
await getMainGuild()?.members?.fetch(res[0].id).catch(e=> e)
if(!discordBot) return null
res[0].flags = res[0].flags | (discordBot.flags && DiscordUserFlags.VERIFIED_BOT ? BotFlags.verifed : 0) | (res[0].trusted ? BotFlags.trusted : 0)
res[0].flags = res[0].flags | (discordBot.flags && DiscordUserFlags.VERIFIED_BOT ? BotFlags.verifed : 0) | (res[0].trusted ? BotFlags.trusted : 0) | (res[0].partnered ? BotFlags.partnered : 0)
res[0].tag = discordBot.discriminator
res[0].avatar = discordBot.avatar
res[0].name = discordBot.username
@ -219,6 +219,12 @@ async function submitBot(id: string, data: AddBotSubmit):Promise<number|Submitte
return await getBotSubmit(botId, date)
}
async function getBotSpec(id: string, userID: string) {
const res = await knex('bots').select(['id', 'token', 'webhook']).where({ id }).andWhere('owners', 'like', `%${userID}%`)
if(!res[0]) return null
return serialize(res[0])
}
async function getImage(url: string) {
const res = await fetch(url)
if(!res.ok) return null
@ -291,6 +297,7 @@ export const get = {
return await getBotSubmit(json.id, json.date)
}))).map(row => serialize(row))
, { cacheMap: new TLRU({ maxStoreSize: 50, maxAgeMs: 60000 }) }),
botSpec: getBotSpec,
list: {
category: new DataLoader(
async (key: string[]) =>