mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 14:30:22 +00:00
chore: added submitBot
This commit is contained in:
parent
2bc8ab8e0d
commit
075caf2cb9
@ -12,6 +12,7 @@ import knex from './Knex'
|
|||||||
import DiscordBot from './DiscordBot'
|
import DiscordBot from './DiscordBot'
|
||||||
import { sign, verify } from './Jwt'
|
import { sign, verify } from './Jwt'
|
||||||
import { serialize } from './Tools'
|
import { serialize } from './Tools'
|
||||||
|
import { AddBotSubmit } from './Yup'
|
||||||
|
|
||||||
export const imageRateLimit = new TLRU<unknown, number>({ maxAgeMs: 60000 })
|
export const imageRateLimit = new TLRU<unknown, number>({ maxAgeMs: 60000 })
|
||||||
|
|
||||||
@ -159,7 +160,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) }
|
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: 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 })
|
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
|
if(res.length === 0) return null
|
||||||
res[0].category = JSON.parse(res[0].category)
|
res[0].category = JSON.parse(res[0].category)
|
||||||
@ -177,6 +178,28 @@ async function getBotSubmits(id: string) {
|
|||||||
return res
|
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<Stream> {
|
async function getImage(url: string):Promise<Stream> {
|
||||||
const res = await fetch(url)
|
const res = await fetch(url)
|
||||||
if(!res.ok) return null
|
if(!res.ok) return null
|
||||||
@ -294,7 +317,7 @@ export const update = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const put = {
|
export const put = {
|
||||||
|
submitBot
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ratelimit = {
|
export const ratelimit = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user