From d156a1ac45dcb98c24fa7a592b4dd27f6b1b3417 Mon Sep 17 00:00:00 2001 From: teddit Date: Mon, 5 Apr 2021 18:02:12 +0200 Subject: [PATCH] add thumbnail image for subreddit rss if full image is missing #175 --- inc/teddit_api/handleSubreddit.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/inc/teddit_api/handleSubreddit.js b/inc/teddit_api/handleSubreddit.js index 8f50c9c..4c2a63b 100644 --- a/inc/teddit_api/handleSubreddit.js +++ b/inc/teddit_api/handleSubreddit.js @@ -52,13 +52,36 @@ module.exports = function() { } } + if(link.preview && link.thumbnail !== 'self') { + if(!link.url.startsWith('/r/') && isGif(link.url)) { + images = { + thumb: await downloadAndSave(link.thumbnail, 'thumb_') + } + } else { + if(link.preview.images[0].resolutions[0]) { + let preview = null + if(!isGif(link.url) && !link.post_hint.includes(':video')) + preview = await downloadAndSave(link.preview.images[0].source.url) + images = { + thumb: await downloadAndSave(link.preview.images[0].resolutions[0].url, 'thumb_'), + preview: preview + } + } + } + } + + link.permalink = `${protocol}://${config.domain}${link.permalink}` if(is_self_link) link.url = link.permalink - if(req.query.hasOwnProperty('full_thumbs')) + if(req.query.hasOwnProperty('full_thumbs')) { + if(!post_image) + post_image = thumbnail + thumbnail = post_image + } let enclosure = '' if(thumbnail != '') {