From acdf33edabc1a07bb9492a028eaaa024de3a19f9 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 26 Mar 2020 09:27:30 +0100 Subject: [PATCH] [Hotfix] Fix crash when a 'post' is `undefined` --- index.js | 13 ++++++++++++- package-lock.json | 8 ++++---- package.json | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index e23a429..4137e16 100755 --- a/index.js +++ b/index.js @@ -30,7 +30,7 @@ const cli = meow( flags: { userAgent: { type: 'string', - default: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0', + default: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0', }, output: { type: 'string', @@ -281,6 +281,17 @@ const maxNameLength = 60; } const parsedPost = allPosts[postId]; + + /** + * Hotfix for posts that can't be parsed due to being "undefined". + * For now it's unclear to me why this is the case, but it seems to be rare + * so I'm just skipping these posts for now. + */ + if (!parsedPost) { + signale.warn(`Could not parse post wih ID: ${postId} -- Skipping.`); + continue; + } + const postMedia = parsedPost.querySelector('.card-attachments'); if (postMedia) { const title = postMedia.querySelector('.card-title'); diff --git a/package-lock.json b/package-lock.json index c4d5b60..45b74a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yiff-dl", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -664,9 +664,9 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "node-html-parser": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-1.2.12.tgz", - "integrity": "sha512-HnmSRgHz+nhXfaii1KBNGwtGBx8ClLZ+GDQHAUNJ43YR3krfJMSMcMwFW8qwrHioPJaiaZ6xrDkcGjlffF0rnw==", + "version": "1.2.13", + "resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-1.2.13.tgz", + "integrity": "sha512-RTG5oDk3nh1oXQGYtQQa9w0v9LjltgzzO1tv3cpXzb9M/UkpFIZ5v4osx3OYAcnWx/ETBXjxs2cgtD9fhn6Bjw==", "requires": { "he": "1.1.1" } diff --git a/package.json b/package.json index 79abdc4..909a200 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yiff-dl", - "version": "1.2.0", + "version": "1.2.1", "description": "Downloads files from creators on Yiff", "main": "index.js", "scripts": { @@ -21,7 +21,7 @@ "filenamify": "^4.1.0", "jsdom": "^15.2.1", "meow": "^5.0.0", - "node-html-parser": "^1.2.12", + "node-html-parser": "^1.2.13", "progress": "^2.0.3", "signale": "^1.4.0" },