mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 06:20:24 +00:00
feat: added vote check endpoint
This commit is contained in:
parent
298939018f
commit
3f579fec4a
@ -4,8 +4,22 @@ import { CaptchaVerify, get, put } from '@utils/Query'
|
|||||||
import RequestHandler from '@utils/RequestHandler'
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
import ResponseWrapper from '@utils/ResponseWrapper'
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
import { checkToken } from '@utils/Csrf'
|
import { checkToken } from '@utils/Csrf'
|
||||||
|
import Yup from '@utils/Yup'
|
||||||
|
import { VOTE_COOLDOWN } from '@utils/Constants'
|
||||||
|
|
||||||
const BotVote = RequestHandler()
|
const BotVote = RequestHandler()
|
||||||
|
.get(async (req: GetApiRequest, res) => {
|
||||||
|
const bot = await get.BotAuthorization(req.headers.authorization)
|
||||||
|
if(!bot) return ResponseWrapper(res, { code: 401 })
|
||||||
|
if(req.query.id !== bot) return ResponseWrapper(res, { code: 403 })
|
||||||
|
const userID = await Yup.string().required().validate(req.query.userID).then(el => el).catch(e => {
|
||||||
|
ResponseWrapper(res, { code: 400, errors: e.errors })
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
if(!userID) return ResponseWrapper(res, { code: 400 })
|
||||||
|
const result = await get.botVote(userID, bot)
|
||||||
|
return ResponseWrapper(res, { code: 200, data: { voted: +new Date() < result + VOTE_COOLDOWN, lastVote: result } })
|
||||||
|
})
|
||||||
.post(async (req: PostApiRequest, res) => {
|
.post(async (req: PostApiRequest, res) => {
|
||||||
const user = await get.Authorization(req.cookies.token)
|
const user = await get.Authorization(req.cookies.token)
|
||||||
if(!user) return ResponseWrapper(res, { code: 401 })
|
if(!user) return ResponseWrapper(res, { code: 401 })
|
||||||
@ -22,14 +36,22 @@ const BotVote = RequestHandler()
|
|||||||
else return ResponseWrapper(res, { code: 429, data: { retryAfter: vote } })
|
else return ResponseWrapper(res, { code: 429, data: { retryAfter: vote } })
|
||||||
})
|
})
|
||||||
|
|
||||||
interface PostApiRequest extends NextApiRequest {
|
interface ApiRequest extends NextApiRequest {
|
||||||
query: {
|
query: {
|
||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
body: {
|
}
|
||||||
|
|
||||||
|
interface GetApiRequest extends ApiRequest {
|
||||||
|
query: {
|
||||||
|
id: string
|
||||||
|
userID: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
interface PostApiRequest extends ApiRequest {
|
||||||
|
body: {
|
||||||
_captcha: string
|
_captcha: string
|
||||||
_csrf: string
|
_csrf: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BotVote
|
export default BotVote
|
||||||
Loading…
x
Reference in New Issue
Block a user