check that post media_metadata exists (fixes #250)

This commit is contained in:
teddit 2021-10-08 06:46:37 +02:00
parent 5a01338428
commit a9f13741bb

View File

@ -260,25 +260,27 @@ async function processJsonPost(json, parsed, user_preferences) {
obj.gallery_items = []; obj.gallery_items = [];
for (var i = 0; i < post.gallery_data.items.length; i++) { for (var i = 0; i < post.gallery_data.items.length; i++) {
let id = post.gallery_data.items[i].media_id; let id = post.gallery_data.items[i].media_id;
if (post.media_metadata[id]) { if (post.media_metadata) {
if (post.media_metadata[id].p) { if (post.media_metadata[id]) {
if (post.media_metadata[id].p[0]) { if (post.media_metadata[id].p) {
let item = { source: null, thumbnail: null, large: null }; if (post.media_metadata[id].p[0]) {
if (post.media_metadata[id].s && post.media_metadata[id].p[0].u) { let item = { source: null, thumbnail: null, large: null };
item = { if (post.media_metadata[id].s && post.media_metadata[id].p[0].u) {
type: post.media_metadata[id].e, item = {
source: await downloadAndSave(post.media_metadata[id].s.u), type: post.media_metadata[id].e,
thumbnail: await downloadAndSave( source: await downloadAndSave(post.media_metadata[id].s.u),
post.media_metadata[id].p[0].u thumbnail: await downloadAndSave(
), post.media_metadata[id].p[0].u
large: await downloadAndSave( ),
post.media_metadata[id].p[ large: await downloadAndSave(
post.media_metadata[id].p.length - 1 post.media_metadata[id].p[
].u post.media_metadata[id].p.length - 1
), ].u
}; ),
};
}
obj.gallery_items.push(item);
} }
obj.gallery_items.push(item);
} }
} }
} }