This commit is contained in:
teddit 2020-12-08 18:37:52 +01:00
parent 6b626a5e14
commit f5a070e6bd
1 changed files with 21 additions and 0 deletions

View File

@ -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)
})()