mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 06:20:24 +00:00
feat: added refresh data
This commit is contained in:
parent
b4b4314268
commit
a174ff69d4
@ -7,8 +7,9 @@ import RequestHandler from '@utils/RequestHandler'
|
|||||||
import ResponseWrapper from '@utils/ResponseWrapper'
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
import { BotStatUpdate, BotStatUpdateSchema } from '@utils/Yup'
|
import { BotStatUpdate, BotStatUpdateSchema } from '@utils/Yup'
|
||||||
import { discordLog } from '@utils/DiscordBot'
|
import { discordLog } from '@utils/DiscordBot'
|
||||||
import { makeDiscordCodeblock } from '@utils/Tools'
|
import { checkUserFlag, makeDiscordCodeblock } from '@utils/Tools'
|
||||||
import { KoreanbotsEndPoints } from '@utils/Constants'
|
import { KoreanbotsEndPoints } from '@utils/Constants'
|
||||||
|
import type { User } from '@types'
|
||||||
|
|
||||||
const limiter = rateLimit({
|
const limiter = rateLimit({
|
||||||
windowMs: 3 * 60 * 1000,
|
windowMs: 3 * 60 * 1000,
|
||||||
@ -24,6 +25,19 @@ const limiter = rateLimit({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const patchLimiter = rateLimit({
|
||||||
|
windowMs: 2 * 60 * 1000,
|
||||||
|
max: 6,
|
||||||
|
statusCode: 429,
|
||||||
|
skipFailedRequests: true,
|
||||||
|
handler: (_req, res) => ResponseWrapper(res, { code: 429 }),
|
||||||
|
keyGenerator: (req) => req.headers['x-forwarded-for'] as string,
|
||||||
|
skip: (_req, res) => {
|
||||||
|
res.removeHeader('X-RateLimit-Global')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const BotStats = RequestHandler().post(limiter)
|
const BotStats = RequestHandler().post(limiter)
|
||||||
.post(async (req: PostApiRequest, res) => {
|
.post(async (req: PostApiRequest, res) => {
|
||||||
const bot = await get.BotAuthorization(req.headers.authorization)
|
const bot = await get.BotAuthorization(req.headers.authorization)
|
||||||
@ -46,9 +60,25 @@ const BotStats = RequestHandler().post(limiter)
|
|||||||
await discordLog('BOT/STATS', botInfo.id, (new MessageEmbed().setDescription(`${botInfo.name} - <@${botInfo.id}> ([${botInfo.id}](${KoreanbotsEndPoints.URL.bot(botInfo.id)}))`)), null, makeDiscordCodeblock(`${botInfo.servers > validated.servers ? '-' : '+'} ${botInfo.servers} -> ${validated.servers} (${botInfo.servers > validated.servers ? '▼' : '▲'}${Math.abs(validated.servers - botInfo.servers)})`, 'diff'))
|
await discordLog('BOT/STATS', botInfo.id, (new MessageEmbed().setDescription(`${botInfo.name} - <@${botInfo.id}> ([${botInfo.id}](${KoreanbotsEndPoints.URL.bot(botInfo.id)}))`)), null, makeDiscordCodeblock(`${botInfo.servers > validated.servers ? '-' : '+'} ${botInfo.servers} -> ${validated.servers} (${botInfo.servers > validated.servers ? '▼' : '▲'}${Math.abs(validated.servers - botInfo.servers)})`, 'diff'))
|
||||||
return ResponseWrapper(res, { code: 200, message: '성공적으로 업데이트 했습니다.'})
|
return ResponseWrapper(res, { code: 200, message: '성공적으로 업데이트 했습니다.'})
|
||||||
})
|
})
|
||||||
|
.patch(patchLimiter).patch(async (req: ApiRequest, res) => {
|
||||||
|
console.log('1')
|
||||||
|
const user = await get.Authorization(req.cookies.token)
|
||||||
|
if (!user) return ResponseWrapper(res, { code: 401 })
|
||||||
|
const userinfo = await get.user.load(user)
|
||||||
|
const bot = await get.bot.load(req.query.id)
|
||||||
|
if(!bot) return ResponseWrapper(res, { code: 404 })
|
||||||
|
if(!(bot.owners as User[]).find(el => el.id === user) && !checkUserFlag(userinfo.flags, 'staff')) return ResponseWrapper(res, { code: 403 })
|
||||||
|
get.bot.clear(req.query.id)
|
||||||
|
return ResponseWrapper(res, { code: 200 })
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
interface PostApiRequest extends NextApiRequest {
|
interface ApiRequest extends NextApiRequest {
|
||||||
|
query: {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
interface PostApiRequest extends ApiRequest {
|
||||||
query: {
|
query: {
|
||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,8 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
<div className='w-full text-center lg:w-1/4'>
|
<div className='w-full text-center lg:w-1/4'>
|
||||||
<DiscordAvatar
|
<DiscordAvatar
|
||||||
userID={data.id}
|
userID={data.id}
|
||||||
className={`w-full ${router.query.id === 'iu' ? 'cursor-heart' : ''}`}
|
size={256}
|
||||||
|
className='w-full'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex-grow px-5 py-12 w-full text-center lg:w-5/12 lg:text-left'>
|
<div className='flex-grow px-5 py-12 w-full text-center lg:w-5/12 lg:text-left'>
|
||||||
@ -148,6 +149,17 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
</h4>
|
</h4>
|
||||||
</LongButton>
|
</LongButton>
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
((data.owners as User[]).find(el => el.id === user?.id) || checkUserFlag(user?.flags, 'staff')) && <LongButton onClick={async() => {
|
||||||
|
const res = await Fetch(`/bots/${data.id}/stats`, { method: 'PATCH'} )
|
||||||
|
if(res.code !== 200) return alert(res.message)
|
||||||
|
else window.location.reload()
|
||||||
|
}}>
|
||||||
|
<h4>
|
||||||
|
<i className='fas fa-sync' /> 정보 갱신하기
|
||||||
|
</h4>
|
||||||
|
</LongButton>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Divider className='px-5' />
|
<Divider className='px-5' />
|
||||||
@ -199,8 +211,7 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
if(!user) return <Login />
|
if(!user) return <Login />
|
||||||
else setReportModal(true)
|
else setReportModal(true)
|
||||||
}} aria-hidden='true'>
|
}} aria-hidden='true'>
|
||||||
<i className='far fa-flag' />
|
<i className='far fa-flag' /> 신고하기
|
||||||
신고하기
|
|
||||||
</a>
|
</a>
|
||||||
<Modal header={`${data.name}#${data.tag} 신고하기`} closeIcon isOpen={reportModal} onClose={() => {
|
<Modal header={`${data.name}#${data.tag} 신고하기`} closeIcon isOpen={reportModal} onClose={() => {
|
||||||
setReportModal(false)
|
setReportModal(false)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user