mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 14:30:22 +00:00
feat: added icon option
This commit is contained in:
parent
3ac7d3f355
commit
a160d891bd
@ -8,7 +8,7 @@ import { get } from '@utils/Query'
|
|||||||
import { BotBadgeType, DiscordEnpoints } from '@utils/Constants'
|
import { BotBadgeType, DiscordEnpoints } from '@utils/Constants'
|
||||||
|
|
||||||
const Widget: NextApiHandler = async(req: ApiRequest, res: NextApiResponse) => {
|
const Widget: NextApiHandler = async(req: ApiRequest, res: NextApiResponse) => {
|
||||||
const { id: param, type, style='flat', scale=1 } = req.query
|
const { id: param, type, style='flat', scale=1, icon=true } = req.query
|
||||||
const splitted = param.split('.')
|
const splitted = param.split('.')
|
||||||
|
|
||||||
const validated = await WidgetOptionsSchema.validate({
|
const validated = await WidgetOptionsSchema.validate({
|
||||||
@ -16,7 +16,8 @@ const Widget: NextApiHandler = async(req: ApiRequest, res: NextApiResponse) => {
|
|||||||
ext: splitted[splitted.length - 1],
|
ext: splitted[splitted.length - 1],
|
||||||
style,
|
style,
|
||||||
type,
|
type,
|
||||||
scale
|
scale,
|
||||||
|
icon
|
||||||
}).then(el=> el).catch(e=> {
|
}).then(el=> el).catch(e=> {
|
||||||
ResponseWrapper(res, { code: 400, errors: e.errors })
|
ResponseWrapper(res, { code: 400, errors: e.errors })
|
||||||
return null
|
return null
|
||||||
@ -34,7 +35,7 @@ const Widget: NextApiHandler = async(req: ApiRequest, res: NextApiResponse) => {
|
|||||||
...BotBadgeType(data)[type],
|
...BotBadgeType(data)[type],
|
||||||
style: validated.style,
|
style: validated.style,
|
||||||
scale: validated.scale,
|
scale: validated.scale,
|
||||||
icon: `data:image/png;base64,${img.toString('base64')}`
|
icon: validated.icon ? `data:image/png;base64,${img.toString('base64')}` : null
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(badgen(badgeData))
|
res.send(badgen(badgeData))
|
||||||
@ -47,6 +48,7 @@ interface ApiRequest extends NextApiRequest {
|
|||||||
id: string
|
id: string
|
||||||
style?: string
|
style?: string
|
||||||
scale?: string
|
scale?: string
|
||||||
|
icon?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,8 @@ export const WidgetOptionsSchema: Yup.SchemaOf<WidgetOptions> = Yup.object({
|
|||||||
ext: Yup.mixed<widgetExt>().oneOf(['svg']).required(),
|
ext: Yup.mixed<widgetExt>().oneOf(['svg']).required(),
|
||||||
type: Yup.mixed<widgetType>().oneOf(['votes', 'servers', 'status']).required(),
|
type: Yup.mixed<widgetType>().oneOf(['votes', 'servers', 'status']).required(),
|
||||||
scale: Yup.number().positive().min(0.5).max(3).required(),
|
scale: Yup.number().positive().min(0.5).max(3).required(),
|
||||||
style: Yup.mixed<'flat'|'classic'>().oneOf(['flat', 'classic']).default('flat')
|
style: Yup.mixed<'flat'|'classic'>().oneOf(['flat', 'classic']).default('flat'),
|
||||||
|
icon: Yup.boolean().default(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
interface WidgetOptions {
|
interface WidgetOptions {
|
||||||
@ -52,6 +53,7 @@ interface WidgetOptions {
|
|||||||
type: widgetType
|
type: widgetType
|
||||||
scale: number
|
scale: number
|
||||||
style: 'flat' | 'classic'
|
style: 'flat' | 'classic'
|
||||||
|
icon: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type widgetType = 'votes' | 'servers' | 'status'
|
type widgetType = 'votes' | 'servers' | 'status'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user