diff --git a/utils/Query.ts b/utils/Query.ts index 1cc6c4a..d32f911 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -12,6 +12,7 @@ import knex from './Knex' import DiscordBot from './DiscordBot' import { sign, verify } from './Jwt' import { serialize } from './Tools' +import { AddBotSubmit } from './Yup' export const imageRateLimit = new TLRU({ maxAgeMs: 60000 }) @@ -159,7 +160,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: string) { +async function getBotSubmit(id: string, date: number) { 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) @@ -177,6 +178,28 @@ async function getBotSubmits(id: string) { return res } +async function submitBot(id: string, data: AddBotSubmit) { + const botId = data.id + const date = Math.round(+new Date()/1000) + await knex('submitted').insert({ + id: botId, + date: date, + owners: JSON.stringify([ id ]), + lib: data.library, + prefix: data.prefix, + intro: data.intro, + desc: data.desc, + web: data.website, + git: data.git, + url: data.url, + category: data.category, + discord: data.discord, + state: 0 + }) + + return await getBotSubmit(botId, date) +} + async function getImage(url: string):Promise { const res = await fetch(url) if(!res.ok) return null @@ -294,7 +317,7 @@ export const update = { } export const put = { - + submitBot } export const ratelimit = {