From a6094a37ec59a7e8700265b83e9314d69c307045 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 21 Feb 2022 23:37:26 +1300 Subject: [PATCH] Embeds may be blocked or have missing captions --- .npmrc | 1 - src/lib/collectors.js | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) delete mode 100644 .npmrc diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 2ae2317..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -loglevel=silent diff --git a/src/lib/collectors.js b/src/lib/collectors.js index a2c941e..e5245a2 100644 --- a/src/lib/collectors.js +++ b/src/lib/collectors.js @@ -431,6 +431,12 @@ function fetchShortcodeData(shortcode) { // find embed const e_embed = root.querySelector(".Embed") + // rate limited? if so, the request to instagram took 5-10 seconds, and returned no other content after + // so in that case there will be no useful elements, and no .Embed element + if (!e_embed) { + throw constants.symbols.RATE_LIMITED + } + // find avatar const e_avatar = root.querySelector(".Avatar") const e_avatarImage = e_avatar.querySelector("img") @@ -473,13 +479,16 @@ function fetchShortcodeData(shortcode) { } }) // extract caption text - const captionText = e_caption.childNodes.slice(4, -3).map(node => { // slice removes unneeded starting and ending whitespace and user handles - if (node.tagName === "br") { - return "\n" - } else { - return node.text - } - }).join("") + let captionText = "" + if (e_caption) { + captionText = e_caption.childNodes.slice(4, -3).map(node => { // slice removes unneeded starting and ending whitespace and user handles + if (node.tagName === "br") { + return "\n" + } else { + return node.text + } + }).join("") + } return { __typename: mediaType, id: e_embed.attributes["data-media-id"],