From c34c32cc35c5ce394d6221e56e4e3f58e3ceb30d Mon Sep 17 00:00:00 2001 From: teddit Date: Sat, 30 Oct 2021 19:26:27 +0200 Subject: [PATCH] check that reddit_video_preview.fallback_url exists (fixes #255) --- inc/processPostMedia.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/inc/processPostMedia.js b/inc/processPostMedia.js index da1b83a..52dc99e 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -92,12 +92,20 @@ module.exports = function() { obj.has_media = true if(!gif_to_mp4) { if(post.preview) { - obj.media = { - source: await downloadAndSave(post.preview.reddit_video_preview.fallback_url), - height: post.preview.reddit_video_preview.height, - width: post.preview.reddit_video_preview.width, - duration: post.preview.reddit_video_preview.duration, - is_gif: true + if(post.preview.reddit_video_preview) { + if(post.preview.reddit_video_preview.fallback_url) { + obj.media = { + source: await downloadAndSave(post.preview.reddit_video_preview.fallback_url), + height: post.preview.reddit_video_preview.height, + width: post.preview.reddit_video_preview.width, + duration: post.preview.reddit_video_preview.duration, + is_gif: true + } + } else { + obj.has_media = false + } + } else { + obj.has_media = false } } else { obj.has_media = false