Fix thumbnail

This commit is contained in:
syuilo 2017-11-16 23:05:12 +09:00
parent a757960c41
commit d81bc3cd21
2 changed files with 11 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@ -50,11 +50,22 @@ interface ISend {
function thumbnail(data: stream.Readable, type: string, resize: number): ISend {
const readable: stream.Readable = (() => {
// 画像ではない場合
if (!/^image\/.*$/.test(type)) {
// 使わないことにしたストリームはしっかり取り壊しておく
data.destroy();
return fs.createReadStream(`${__dirname}/assets/not-an-image.png`);
}
const imageType = type.split('/')[1];
// 画像でもPNGかJPEGでないならダメ
if (imageType != 'png' && imageType != 'jpeg') {
// 使わないことにしたストリームはしっかり取り壊しておく
data.destroy();
return fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`);
}
return data;
})();