mirror of
https://github.com/koreanbots/core.git
synced 2025-12-17 06:40:24 +00:00
feat: private api changes
This commit is contained in:
parent
007e5816d6
commit
daf0d85c83
32
pages/api/v2/management/bots/submits/[id]/[date]/deny.ts
Normal file
32
pages/api/v2/management/bots/submits/[id]/[date]/deny.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { NextApiRequest } from 'next'
|
||||||
|
import { MessageEmbed } from 'discord.js'
|
||||||
|
|
||||||
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
|
import { get, update } from '@utils/Query'
|
||||||
|
import { DiscordBot, getBotReviewLogChannel } from '@utils/DiscordBot'
|
||||||
|
import { KoreanbotsEndPoints } from '@utils/Constants'
|
||||||
|
|
||||||
|
const DenyBotSubmit = RequestHandler()
|
||||||
|
.post(async (req: ApiRequest, res) => {
|
||||||
|
const bot = await get.BotAuthorization(req.headers.authorization)
|
||||||
|
if(bot !== DiscordBot.user.id) return ResponseWrapper(res, { code: 403 })
|
||||||
|
const submit = await get.botSubmit.load(JSON.stringify({ id: req.query.id, date: req.query.date }))
|
||||||
|
if(!submit) return ResponseWrapper(res, { code: 404 })
|
||||||
|
await update.denyBotSubmission(submit.id, submit.date, req.body.reason)
|
||||||
|
get.botSubmit.clear(JSON.stringify({ id: req.query.id, date: req.query.date }))
|
||||||
|
await getBotReviewLogChannel().send(new MessageEmbed().setTitle('거부 됨').setColor('RED').setDescription(`[${submit.id}/${submit.date}](${KoreanbotsEndPoints.URL.submittedBot(submit.id, submit.date)})`).setTimestamp())
|
||||||
|
return ResponseWrapper(res, { code: 200 })
|
||||||
|
})
|
||||||
|
|
||||||
|
interface ApiRequest extends NextApiRequest {
|
||||||
|
query: {
|
||||||
|
id: string
|
||||||
|
date: string
|
||||||
|
}
|
||||||
|
body: {
|
||||||
|
reason?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DenyBotSubmit
|
||||||
24
pages/api/v2/management/bots/submits/[id]/[date]/index.ts
Normal file
24
pages/api/v2/management/bots/submits/[id]/[date]/index.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { NextApiRequest } from 'next'
|
||||||
|
|
||||||
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
|
import { get } from '@utils/Query'
|
||||||
|
import { DiscordBot } from '@utils/DiscordBot'
|
||||||
|
|
||||||
|
const BotSubmit = RequestHandler()
|
||||||
|
.get(async (req: ApiRequest, res) => {
|
||||||
|
const bot = await get.BotAuthorization(req.headers.authorization)
|
||||||
|
if(bot !== DiscordBot.user.id) return ResponseWrapper(res, { code: 403 })
|
||||||
|
const submit = await get.botSubmit.load(JSON.stringify({ id: req.query.id, date: req.query.date }))
|
||||||
|
if(!submit) return ResponseWrapper(res, { code: 404 })
|
||||||
|
return ResponseWrapper(res, { code: 200, data: submit })
|
||||||
|
})
|
||||||
|
|
||||||
|
interface ApiRequest extends NextApiRequest {
|
||||||
|
query: {
|
||||||
|
id: string
|
||||||
|
date: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BotSubmit
|
||||||
23
pages/api/v2/management/bots/submits/[id]/index.ts
Normal file
23
pages/api/v2/management/bots/submits/[id]/index.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { NextApiRequest } from 'next'
|
||||||
|
|
||||||
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
|
import { get } from '@utils/Query'
|
||||||
|
import { DiscordBot } from '@utils/DiscordBot'
|
||||||
|
|
||||||
|
const BotSubmit = RequestHandler()
|
||||||
|
.get(async (req: ApiRequest, res) => {
|
||||||
|
const bot = await get.BotAuthorization(req.headers.authorization)
|
||||||
|
if(bot !== DiscordBot.user.id) return ResponseWrapper(res, { code: 403 })
|
||||||
|
const submits = await get.botSubmitList()
|
||||||
|
const submit = submits.find(el => el.id === req.query.id)
|
||||||
|
if(!submit) return ResponseWrapper(res, { code: 404 })
|
||||||
|
return ResponseWrapper(res, { code: 200, data: submit })
|
||||||
|
})
|
||||||
|
|
||||||
|
interface ApiRequest extends NextApiRequest {
|
||||||
|
query: {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default BotSubmit
|
||||||
9
pages/api/v2/management/index.ts
Normal file
9
pages/api/v2/management/index.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
|
|
||||||
|
const BotSubmits = RequestHandler()
|
||||||
|
.get(async (_req, res) => {
|
||||||
|
return ResponseWrapper(res, { code: 403, message: 'Private API' })
|
||||||
|
})
|
||||||
|
|
||||||
|
export default BotSubmits
|
||||||
@ -188,6 +188,18 @@ export const DiscordEnpoints = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const KoreanbotsEndPoints = {
|
export const KoreanbotsEndPoints = {
|
||||||
|
OG: class {
|
||||||
|
static root = 'https://og.kbots.link'
|
||||||
|
static bot(id: string, name: string, bio: string, tags: string[], stats: string[]) {
|
||||||
|
const u = new URL(this.root)
|
||||||
|
u.pathname = name
|
||||||
|
u.searchParams.append('image', KoreanbotsEndPoints.CDN.avatar(id, { format: 'webp', size: 256 }))
|
||||||
|
u.searchParams.append('bio', bio)
|
||||||
|
tags.map(t => u.searchParams.append('tags', t))
|
||||||
|
stats.map(s => u.searchParams.append('stats', s))
|
||||||
|
return u.href
|
||||||
|
}
|
||||||
|
},
|
||||||
CDN: class {
|
CDN: class {
|
||||||
static root = '/api/image'
|
static root = '/api/image'
|
||||||
static avatar (id: string, options: KoreanbotsImageOptions) { return makeImageURL(`${this.root}/discord/avatars/${id}`, options) }
|
static avatar (id: string, options: KoreanbotsImageOptions) { return makeImageURL(`${this.root}/discord/avatars/${id}`, options) }
|
||||||
@ -195,6 +207,7 @@ export const KoreanbotsEndPoints = {
|
|||||||
URL: class {
|
URL: class {
|
||||||
static root = process.env.KOREANBOTS_URL || 'https://koreanbots.dev'
|
static root = process.env.KOREANBOTS_URL || 'https://koreanbots.dev'
|
||||||
static bot (id: string) { return `${this.root}/bots/${id}` }
|
static bot (id: string) { return `${this.root}/bots/${id}` }
|
||||||
|
static user (id: string) { return `${this.root}/users/${id}` }
|
||||||
static submittedBot(id: string, date: number) { return `${this.root}/pendingBots/${id}/${date}` }
|
static submittedBot(id: string, date: number) { return `${this.root}/pendingBots/${id}/${date}` }
|
||||||
},
|
},
|
||||||
baseAPI: '/api/v2',
|
baseAPI: '/api/v2',
|
||||||
|
|||||||
@ -381,6 +381,10 @@ async function getBotSubmitList() {
|
|||||||
return await Promise.all(res.map(b => get.botSubmit.load(JSON.stringify({ id: b.id, date: b.date }))))
|
return await Promise.all(res.map(b => get.botSubmit.load(JSON.stringify({ id: b.id, date: b.date }))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function denyBotSubmission(id: string, date: number, reason?: string) {
|
||||||
|
await knex('submitted').update({ state: 2 }).where({ state: 0, id, date, reason: reason || null })
|
||||||
|
}
|
||||||
|
|
||||||
export const get = {
|
export const get = {
|
||||||
discord: {
|
discord: {
|
||||||
user: new DataLoader(
|
user: new DataLoader(
|
||||||
@ -475,7 +479,8 @@ export const update = {
|
|||||||
updateServer,
|
updateServer,
|
||||||
Github,
|
Github,
|
||||||
bot: updateBot,
|
bot: updateBot,
|
||||||
botOwners: updateOwner
|
botOwners: updateOwner,
|
||||||
|
denyBotSubmission
|
||||||
}
|
}
|
||||||
|
|
||||||
export const put = {
|
export const put = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user