parent
0760d17d82
commit
8b77d16a72
|
@ -62,8 +62,13 @@ if (color[0] === ':') {
|
|||
|
||||
badge(badgeData, function produceOutput(svg) {
|
||||
if (/png|jpg|gif/.test(format)) {
|
||||
svg2img(svg, format, function (data) {
|
||||
svg2img(svg, format, function (err, data) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.stdout.write(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(svg);
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = function (svg, format, callback) {
|
|||
if (imgCache.has(cacheIndex)) {
|
||||
// We own a cache for this svg conversion.
|
||||
var result = imgCache.get(cacheIndex);
|
||||
callback(result);
|
||||
callback(null, result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,15 +20,13 @@ module.exports = function (svg, format, callback) {
|
|||
.density(90)
|
||||
.background(format === 'jpg' ? '#FFFFFF' : 'none')
|
||||
.flatten()
|
||||
.stream(format, function (err, stdout, stderr) {
|
||||
if (err) { console.error(err); return; }
|
||||
var chunks = [];
|
||||
stdout.on('data', function(chunk) { chunks.push(chunk); });
|
||||
stdout.on('finish', function() {
|
||||
var result = Buffer.concat(chunks);
|
||||
imgCache.set(cacheIndex, result);
|
||||
callback(result);
|
||||
});
|
||||
.toBuffer(format, function (err, data) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
imgCache.set(cacheIndex, data);
|
||||
callback(null, data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
6
public/500.html
Normal file
6
public/500.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<!doctype html><meta charset=utf-8><title>A server error occurred</title>
|
||||
|
||||
<h1> I have nothing to offer for this request </h1>
|
||||
<p> … but blood, toil, tears and sweat.
|
||||
</p>
|
||||
<p>And trying again later.</p>
|
|
@ -6127,8 +6127,13 @@ function sendSVG(res, askres, end) {
|
|||
|
||||
function sendOther(format, res, askres, end) {
|
||||
askres.setHeader('Content-Type', 'image/' + format);
|
||||
svg2img(res, format, function (data) {
|
||||
svg2img(res, format, function (err, data) {
|
||||
if (err) {
|
||||
console.error('svg2img error', err);
|
||||
end(null, {template: '500.html'});
|
||||
} else {
|
||||
end(null, {template: streamFromString(data)});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ describe('The rasterizer', function () {
|
|||
|
||||
it('should produce PNG', function(done) {
|
||||
badge({ text: ['cactus', 'grown'], format: 'svg' }, svg => {
|
||||
svg2img(svg, 'png', data => {
|
||||
svg2img(svg, 'png', (err, data) => {
|
||||
assert.equal(err, null);
|
||||
assert.ok(isPng(data));
|
||||
done();
|
||||
});
|
||||
|
@ -21,12 +22,14 @@ describe('The rasterizer', function () {
|
|||
|
||||
it('should cache its results', function(done) {
|
||||
badge({ text: ['will-this', 'be-cached?'], format: 'svg' }, svg => {
|
||||
svg2img(svg, 'png', data1 => {
|
||||
assert.ok(isPng(data1));
|
||||
svg2img(svg, 'png', (err, data) => {
|
||||
assert.equal(err, null);
|
||||
assert.ok(isPng(data));
|
||||
assert.equal(cacheGet.called, false);
|
||||
|
||||
svg2img(svg, 'png', data2 => {
|
||||
assert.ok(isPng(data2));
|
||||
svg2img(svg, 'png', (err, data) => {
|
||||
assert.equal(err, null);
|
||||
assert.ok(isPng(data));
|
||||
assert.ok(cacheGet.calledOnce);
|
||||
|
||||
done();
|
||||
|
|
Loading…
Reference in New Issue
Block a user