Add a thorough MIME image type check (#753)

#555 
https://github.com/DIYgod/RSSHub/issues/555#issuecomment-422837421
This commit is contained in:
Henry Wang
2018-09-21 11:37:11 +01:00
committed by DIYgod
parent 4d9ae9cd05
commit d76b097b2e

View File

@@ -84,12 +84,28 @@ module.exports = {
// 5. 图片
if (item.pictures) {
item.pictures.forEach(
(pic) =>
(description += `<br/><picture><source srcset="${pic.picUrl.split('/thumbnail/')[0]}/strip/format/webp" type="image/webp"><source srcset="${pic.picUrl.split('?imageMogr2/')[0]}" type="image/jpeg"><img src="${
item.pictures.forEach((pic) => {
if (pic.format === 'gif') {
description += `<img src="${pic.picUrl.split('?imageMogr2/')[0]}"></picture>`;
} else {
// jpeg, bmp, png, gif, webp
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
let type = 'jpeg';
switch (pic.format) {
case 'bmp':
type = 'bmp';
break;
case 'png':
type = 'png';
break;
default:
break;
}
description += `<br/><picture><source srcset="${pic.picUrl.split('/thumbnail/')[0]}/strip/format/webp" type="image/webp"><source srcset="${
pic.picUrl.split('?imageMogr2/')[0]
}"></picture>`)
);
}" type="image/${type}"><img src="${pic.picUrl.split('?imageMogr2/')[0]}"></picture>`;
}
});
}
// rss标题