mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: added get botSubmits list api
This commit is contained in:
parent
63b43d2331
commit
debd0e6453
@ -15,6 +15,7 @@ UPDATE `bots` SET bg=NULL where bg='false' or bg='';
|
||||
UPDATE `bots` SET banner=NULL where banner='false' or banner='';
|
||||
ALTER TABLE `bots` ADD COLUMN webhook TEXT DEFAULT NULL;
|
||||
ALTER TABLE `bots` CHANGE id id VARCHAR(50) NOT NULL PRIMARY KEY;
|
||||
ALTER TABLE `bots` CHANGE token token TEXT DEFAULT NULL;
|
||||
ALTER TABLE `bots` ENGINE=mroonga;
|
||||
ALTER TABLE `bots` COMMENT='engine "innodb"';
|
||||
ALTER TABLE `bots` ADD `flags` INT NOT NULL DEFAULT 0;
|
||||
|
||||
14
pages/api/v2/management/botSubmits/index.ts
Normal file
14
pages/api/v2/management/botSubmits/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import RequestHandler from '@utils/RequestHandler'
|
||||
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||
import { get } from '@utils/Query'
|
||||
import { DiscordBot } from '@utils/DiscordBot'
|
||||
|
||||
const BotSubmits = RequestHandler()
|
||||
.get(async (req, res) => {
|
||||
const bot = await get.BotAuthorization(req.headers.authorization)
|
||||
if(bot !== DiscordBot.user.id) return ResponseWrapper(res, { code: 403 })
|
||||
const submits = await get.botSubmitList()
|
||||
return ResponseWrapper(res, { code: 200, data: submits })
|
||||
})
|
||||
|
||||
export default BotSubmits
|
||||
@ -162,7 +162,7 @@ async function getBotList(type: ListType, page = 1, query?: string):Promise<BotL
|
||||
return { type, data: (await Promise.all(res.map(async el => await getBot(el.id)))).map(r=> ({...r})), currentPage: page, totalPage: Math.ceil(Number(count) / 16) }
|
||||
}
|
||||
|
||||
async function getBotSubmit(id: string, date: number) {
|
||||
async function getBotSubmit(id: string, date: number): Promise<SubmittedBot> {
|
||||
const res = await knex('submitted').select(['id', 'date', 'category', 'lib', 'prefix', 'intro', 'desc', 'url', 'web', 'git', 'discord', 'state', 'owners', 'reason']).where({ id, date })
|
||||
if(res.length === 0) return null
|
||||
res[0].category = JSON.parse(res[0].category)
|
||||
@ -170,7 +170,7 @@ async function getBotSubmit(id: string, date: number) {
|
||||
return res[0]
|
||||
}
|
||||
|
||||
async function getBotSubmits(id: string) {
|
||||
async function getBotSubmits(id: string): Promise<SubmittedBot[]> {
|
||||
if(!id) return []
|
||||
let res = await knex('submitted').select(['id', 'date', 'category', 'lib', 'prefix', 'intro', 'desc', 'url', 'web', 'git', 'discord', 'state', 'owners', 'reason']).orderBy('date', 'desc').where('owners', 'LIKE', `%${id}%`)
|
||||
res = await Promise.all(res.map(async el=> {
|
||||
@ -374,6 +374,13 @@ export async function CaptchaVerify(response: string): Promise<boolean> {
|
||||
return res.success
|
||||
}
|
||||
|
||||
// Private APIs
|
||||
|
||||
async function getBotSubmitList() {
|
||||
const res = await knex('submitted').select(['id', 'date']).where({ state: 0 })
|
||||
return await Promise.all(res.map(b => get.botSubmit.load(JSON.stringify({ id: b.id, date: b.date }))))
|
||||
}
|
||||
|
||||
export const get = {
|
||||
discord: {
|
||||
user: new DataLoader(
|
||||
@ -457,7 +464,8 @@ export const get = {
|
||||
},
|
||||
botVote: getBotVote,
|
||||
Authorization,
|
||||
BotAuthorization
|
||||
BotAuthorization,
|
||||
botSubmitList: getBotSubmitList
|
||||
}
|
||||
|
||||
export const update = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user