Simplify serve-badge

pull/282/head
Amio 2019-06-03 22:19:17 +08:00
rodzic e534276e0c
commit 14c4bfe6f7
2 zmienionych plików z 5 dodań i 6 usunięć

Wyświetl plik

@ -44,7 +44,7 @@ export function badgenServe (handlers: BadgenServeHandlers): Function {
color: 'grey'
}
if (req.headers.host.startsWith('flat.') && query.style === undefined) {
if (query.style === undefined && req.headers.host.startsWith('flat.')) {
query.style = 'flat'
}

Wyświetl plik

@ -7,15 +7,14 @@ type ServeBadgeOptions = {
code?: number
sMaxAge?: number,
query?: { [key: string]: any },
params?: BadgenParams
params: BadgenParams
}
export default function (req, res, options: ServeBadgeOptions) {
const { code = 200, sMaxAge = 10800, query = {}, params } = options
const hostStyle = req.headers.host === 'flat.badgen.net' ? 'flat' : undefined
const { subject, status, color } = params || req.params
const { style, label, list, icon, iconWidth, color: queryColor } = query || req.query
const { subject, status, color } = params
const { style, label, list, icon, iconWidth, color: queryColor } = query
const _icon = icons[icon === '' ? subject : icon] || {
base64: icon,
width: iconWidth
@ -25,7 +24,7 @@ export default function (req, res, options: ServeBadgeOptions) {
subject: typeof label !== 'undefined' ? label : subject,
status: String(list ? status.replace(/,/g, ' | ') : status),
color: queryColor || color,
style: style || hostStyle,
style: style,
icon: _icon.base64,
iconWidth: _icon.width
})