diff --git a/migrate.sql b/migrate.sql index 0dccdf5..b2d15a2 100644 --- a/migrate.sql +++ b/migrate.sql @@ -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; diff --git a/pages/api/v2/management/botSubmits/index.ts b/pages/api/v2/management/botSubmits/index.ts new file mode 100644 index 0000000..8f6381c --- /dev/null +++ b/pages/api/v2/management/botSubmits/index.ts @@ -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 \ No newline at end of file diff --git a/utils/Query.ts b/utils/Query.ts index d23d069..f20ba37 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -162,7 +162,7 @@ async function getBotList(type: ListType, page = 1, query?: string):Promise 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 { 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 { 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 { 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 = {