From a9f13741bbf52cf6d21aec1938c3d81fe8231725 Mon Sep 17 00:00:00 2001 From: teddit Date: Fri, 8 Oct 2021 06:46:37 +0200 Subject: [PATCH] check that post media_metadata exists (fixes #250) --- inc/processJsonPost.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 754b589..f382ee5 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -260,25 +260,27 @@ async function processJsonPost(json, parsed, user_preferences) { obj.gallery_items = []; for (var i = 0; i < post.gallery_data.items.length; i++) { let id = post.gallery_data.items[i].media_id; - if (post.media_metadata[id]) { - if (post.media_metadata[id].p) { - if (post.media_metadata[id].p[0]) { - let item = { source: null, thumbnail: null, large: null }; - if (post.media_metadata[id].s && post.media_metadata[id].p[0].u) { - item = { - type: post.media_metadata[id].e, - source: await downloadAndSave(post.media_metadata[id].s.u), - thumbnail: await downloadAndSave( - post.media_metadata[id].p[0].u - ), - large: await downloadAndSave( - post.media_metadata[id].p[ - post.media_metadata[id].p.length - 1 - ].u - ), - }; + if (post.media_metadata) { + if (post.media_metadata[id]) { + if (post.media_metadata[id].p) { + if (post.media_metadata[id].p[0]) { + let item = { source: null, thumbnail: null, large: null }; + if (post.media_metadata[id].s && post.media_metadata[id].p[0].u) { + item = { + type: post.media_metadata[id].e, + source: await downloadAndSave(post.media_metadata[id].s.u), + thumbnail: await downloadAndSave( + post.media_metadata[id].p[0].u + ), + large: await downloadAndSave( + post.media_metadata[id].p[ + post.media_metadata[id].p.length - 1 + ].u + ), + }; + } + obj.gallery_items.push(item); } - obj.gallery_items.push(item); } } }