mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 22:10:24 +00:00
feat: make all API Requests require authorization (#686)
This commit is contained in:
parent
3af7bd3079
commit
a2adbf116e
@ -39,6 +39,10 @@ const patchLimiter = rateLimit({
|
|||||||
})
|
})
|
||||||
const Bots = RequestHandler()
|
const Bots = RequestHandler()
|
||||||
.get(async (req: GetApiRequest, res) => {
|
.get(async (req: GetApiRequest, res) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const bot = await get.bot.load(req.query.id)
|
const bot = await get.bot.load(req.query.id)
|
||||||
if (!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
if (!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
||||||
else {
|
else {
|
||||||
@ -200,7 +204,7 @@ const Bots = RequestHandler()
|
|||||||
|
|
||||||
const isPerkAvailable =
|
const isPerkAvailable =
|
||||||
checkBotFlag(bot.flags, 'partnered') || checkBotFlag(bot.flags, 'trusted')
|
checkBotFlag(bot.flags, 'partnered') || checkBotFlag(bot.flags, 'trusted')
|
||||||
|
|
||||||
const userInfo = await get.user.load(user)
|
const userInfo = await get.user.load(user)
|
||||||
if (
|
if (
|
||||||
['reported', 'blocked', 'archived'].includes(bot.state) &&
|
['reported', 'blocked', 'archived'].includes(bot.state) &&
|
||||||
@ -219,7 +223,8 @@ const Bots = RequestHandler()
|
|||||||
const csrfValidated = checkToken(req, res, req.body._csrf)
|
const csrfValidated = checkToken(req, res, req.body._csrf)
|
||||||
if (!csrfValidated) return
|
if (!csrfValidated) return
|
||||||
|
|
||||||
const validated: ManageBot = await getManageBotSchema(isPerkAvailable).validate(req.body, { abortEarly: false })
|
const validated: ManageBot = await getManageBotSchema(isPerkAvailable)
|
||||||
|
.validate(req.body, { abortEarly: false })
|
||||||
.then((el) => el)
|
.then((el) => el)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
ResponseWrapper(res, { code: 400, errors: e.errors })
|
ResponseWrapper(res, { code: 400, errors: e.errors })
|
||||||
|
|||||||
@ -4,7 +4,11 @@ import ResponseWrapper from '@utils/ResponseWrapper'
|
|||||||
|
|
||||||
import { Bot, List } from '@types'
|
import { Bot, List } from '@types'
|
||||||
|
|
||||||
const NewList = RequestHandler().get(async (_req, res) => {
|
const NewList = RequestHandler().get(async (req, res) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const result = await get.list.new.load(1)
|
const result = await get.list.new.load(1)
|
||||||
return ResponseWrapper<List<Bot>>(res, { code: 200, data: result })
|
return ResponseWrapper<List<Bot>>(res, { code: 200, data: result })
|
||||||
})
|
})
|
||||||
|
|||||||
@ -6,6 +6,10 @@ import { Bot, List } from '@types'
|
|||||||
import Yup from '@utils/Yup'
|
import Yup from '@utils/Yup'
|
||||||
|
|
||||||
const VotesList = RequestHandler().get(async (req, res) => {
|
const VotesList = RequestHandler().get(async (req, res) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const page = await Yup.number()
|
const page = await Yup.number()
|
||||||
.positive()
|
.positive()
|
||||||
.integer()
|
.integer()
|
||||||
|
|||||||
@ -8,6 +8,10 @@ import { SearchQuerySchema } from '@utils/Yup'
|
|||||||
import { Bot, Server, List } from '@types'
|
import { Bot, Server, List } from '@types'
|
||||||
|
|
||||||
const Search = RequestHandler().get(async (req: ApiRequest, res) => {
|
const Search = RequestHandler().get(async (req: ApiRequest, res) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const validated = await SearchQuerySchema.validate({ q: req.query.q || req.query.query, page: 1 })
|
const validated = await SearchQuerySchema.validate({ q: req.query.q || req.query.query, page: 1 })
|
||||||
.then((el) => el)
|
.then((el) => el)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
|||||||
@ -8,6 +8,10 @@ import { SearchQuerySchema } from '@utils/Yup'
|
|||||||
import { Bot, List } from '@types'
|
import { Bot, List } from '@types'
|
||||||
|
|
||||||
const SearchBots = RequestHandler().get(async (req: ApiRequest, res: NextApiResponse) => {
|
const SearchBots = RequestHandler().get(async (req: ApiRequest, res: NextApiResponse) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const validated = await SearchQuerySchema.validate({
|
const validated = await SearchQuerySchema.validate({
|
||||||
q: req.query.q || req.query.query,
|
q: req.query.q || req.query.query,
|
||||||
page: req.query.page,
|
page: req.query.page,
|
||||||
|
|||||||
@ -8,6 +8,10 @@ import { SearchQuerySchema } from '@utils/Yup'
|
|||||||
import { Server, List } from '@types'
|
import { Server, List } from '@types'
|
||||||
|
|
||||||
const SearchServers = RequestHandler().get(async (req: ApiRequest, res: NextApiResponse) => {
|
const SearchServers = RequestHandler().get(async (req: ApiRequest, res: NextApiResponse) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const validated = await SearchQuerySchema.validate({
|
const validated = await SearchQuerySchema.validate({
|
||||||
q: req.query.q || req.query.query,
|
q: req.query.q || req.query.query,
|
||||||
page: req.query.page,
|
page: req.query.page,
|
||||||
|
|||||||
@ -36,6 +36,10 @@ const patchLimiter = rateLimit({
|
|||||||
})
|
})
|
||||||
const Servers = RequestHandler()
|
const Servers = RequestHandler()
|
||||||
.get(async (req: GetApiRequest, res) => {
|
.get(async (req: GetApiRequest, res) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const server = await get.server.load(req.query.id)
|
const server = await get.server.load(req.query.id)
|
||||||
if (!server) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 서버 입니다.' })
|
if (!server) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 서버 입니다.' })
|
||||||
else {
|
else {
|
||||||
|
|||||||
@ -5,6 +5,10 @@ import ResponseWrapper from '@utils/ResponseWrapper'
|
|||||||
import { get } from '@utils/Query'
|
import { get } from '@utils/Query'
|
||||||
|
|
||||||
const ServerOwners = RequestHandler().get(async (req: GetApiRequest, res) => {
|
const ServerOwners = RequestHandler().get(async (req: GetApiRequest, res) => {
|
||||||
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const owners = await get.serverOwners(req.query.id)
|
const owners = await get.serverOwners(req.query.id)
|
||||||
if (!owners) return ResponseWrapper(res, { code: 404 })
|
if (!owners) return ResponseWrapper(res, { code: 404 })
|
||||||
return ResponseWrapper(res, { code: 200, data: owners })
|
return ResponseWrapper(res, { code: 200, data: owners })
|
||||||
|
|||||||
@ -5,7 +5,10 @@ import ResponseWrapper from '@utils/ResponseWrapper'
|
|||||||
import RequestHandler from '@utils/RequestHandler'
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
|
|
||||||
const Users = RequestHandler().get(async (req: ApiRequest, res) => {
|
const Users = RequestHandler().get(async (req: ApiRequest, res) => {
|
||||||
console.log(req.query)
|
const auth = req.headers.authorization
|
||||||
|
? await get.BotAuthorization(req.headers.authorization)
|
||||||
|
: await get.Authorization(req.cookies.token)
|
||||||
|
if (!auth) return ResponseWrapper(res, { code: 401 })
|
||||||
const user = await get.user.load(req.query?.id)
|
const user = await get.user.load(req.query?.id)
|
||||||
if (!user) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 유저 입니다.' })
|
if (!user) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 유저 입니다.' })
|
||||||
else return ResponseWrapper(res, { code: 200, data: user })
|
else return ResponseWrapper(res, { code: 200, data: user })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user