From 2773a5cce6ffc806147cc8228aae5894ae12f830 Mon Sep 17 00:00:00 2001 From: Amio Date: Tue, 11 Jun 2019 00:13:27 +0800 Subject: [PATCH] Better handle style switch --- libs/badgen-serve.ts | 8 ++++---- libs/serve-badge.ts | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/badgen-serve.ts b/libs/badgen-serve.ts index 1fd734d..2f5e630 100644 --- a/libs/badgen-serve.ts +++ b/libs/badgen-serve.ts @@ -47,10 +47,10 @@ export function badgenServe (handlers: BadgenServeHandlers): Function { params.subject = simpleDecode(params.subject) params.status = simpleDecode(params.status) - if (query.style === undefined - && process.env.BADGE_STYLE === 'flat' - || req.headers.host.startsWith('flat')) { - query.style = 'flat' + if (query.style === undefined) { + if ((req.headers[':authority'] || req.headers.host).startsWith('flat')) { + query.style = 'flat' + } } return serveBadge(req, res, { params, query }) diff --git a/libs/serve-badge.ts b/libs/serve-badge.ts index ef2c8d3..be4b2d2 100644 --- a/libs/serve-badge.ts +++ b/libs/serve-badge.ts @@ -14,7 +14,8 @@ export default function (req, res, options: ServeBadgeOptions) { const { code = 200, sMaxAge = 10800, query = {}, params } = options const { subject, status, color } = params - const { style, label, list, icon, iconWidth, color: queryColor } = query + const { label, list, icon, iconWidth } = query + const _icon = icons[icon === '' ? subject : icon] || { base64: icon, width: iconWidth @@ -22,9 +23,9 @@ export default function (req, res, options: ServeBadgeOptions) { const badge = badgen({ subject: typeof label !== 'undefined' ? label : subject, - status: String(list ? status.replace(/,/g, ' | ') : status), - color: queryColor || color, - style: style, + status: list ? String(status).replace(/,/g, ' | ') : String(status), + color: query.color || color, + style: query.style || process.env.BADGE_STYLE, icon: _icon.base64, iconWidth: _icon.width })