From f5a070e6bd742410bfde72b4fa033561fde6bccc Mon Sep 17 00:00:00 2001 From: teddit Date: Tue, 8 Dec 2020 18:37:52 +0100 Subject: [PATCH] fix #50 --- inc/processPostMedia.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/inc/processPostMedia.js b/inc/processPostMedia.js index b637a7e..cbda0e2 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -1,4 +1,5 @@ module.exports = function() { + const config = require('../config') this.processPostMedia = (obj, post, post_media, has_gif, reddit_video, gif_to_mp4) => { return new Promise(resolve => { (async () => { @@ -123,6 +124,26 @@ module.exports = function() { } } } + } else { + /** + * Sometimes post has an image, but all the common keys which are implying + * that the post has an iamge, are null or don't exist. Awesome Reddit! + */ + if(!post_media && !has_gif && !post.gallery_data && post.url != '') { + try { + let u = new URL(post.url) + if(config.valid_media_domains.includes(u.hostname)) { + let ext = u.pathname.split('.')[1] + if(ext === 'jpg' || ext === 'png') { + obj.images = { + source: await downloadAndSave(post.url) + } + } + } + } catch(error) { + //console.error(Invalid URL supplied when trying to fetch an image', error) + } + } } resolve(obj) })()