Server: allow arbitrary hex colors.
Fixes #12 since that ensures Buckler parity.
This commit is contained in:
parent
5612084749
commit
c73f7d098f
10
server.js
10
server.js
|
@ -15,6 +15,8 @@ function escapeFormat(t) {
|
|||
.replace(/__/g, '_').replace(/--/g, '-');
|
||||
}
|
||||
|
||||
function sixHex(s) { return /^[0-9a-fA-F]{6}$/.test(s); }
|
||||
|
||||
camp.route(/^\/(([^-]|--)+)-(([^-]|--)+)-(([^-]|--)+).svg$/,
|
||||
function(data, match, end, ask) {
|
||||
var subject = escapeFormat(match[1]);
|
||||
|
@ -22,7 +24,13 @@ camp.route(/^\/(([^-]|--)+)-(([^-]|--)+)-(([^-]|--)+).svg$/,
|
|||
var color = escapeFormat(match[5]);
|
||||
ask.res.setHeader('Content-Type', 'image/svg+xml');
|
||||
try {
|
||||
badge({text: [subject, status], colorscheme: color}, function(res) {
|
||||
var badgeData = {text: [subject, status]};
|
||||
if (sixHex(color)) {
|
||||
badgeData.colorB = '#' + color;
|
||||
} else {
|
||||
badgeData.colorscheme = color;
|
||||
}
|
||||
badge(badgeData, function(res) {
|
||||
end(null, {template: streamFromString(res)});
|
||||
});
|
||||
} catch(e) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user