From 4af6aa85d36ad5207855c666d0895c73e624d2fa Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:54 +0200 Subject: [PATCH] Fixed obsolete eroshare extract single album item property. Throwing error when imgur album and image info fetch fails. Main catch method console log colored red. --- src/app.js | 3 +-- src/dissectLink.js | 2 +- src/methods/eroshare.js | 2 +- src/methods/imgurAlbum.js | 6 +++++- src/methods/imgurImage.js | 6 +++++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app.js b/src/app.js index a200d80..8136a42 100644 --- a/src/app.js +++ b/src/app.js @@ -12,7 +12,6 @@ const reddit = new snoowrap(config.reddit.api); const curateSubmissions = require('./curate/submissions.js'); const curateUser = require('./curate/user.js'); -const methods = require('./methods/methods.js'); const interpolate = require('./interpolate.js'); const fetchInfo = require('./fetch/info.js'); @@ -57,6 +56,6 @@ users.forEach(username => { }).then(({user, posts}) => { return fetchContent(posts, user); }).catch(error => { - return console.log(error); + return console.log('\x1b[31m%s\x1b[0m', error); }); }); diff --git a/src/dissectLink.js b/src/dissectLink.js index 83ab086..26d6172 100644 --- a/src/dissectLink.js +++ b/src/dissectLink.js @@ -33,7 +33,7 @@ const hosts = [{ }, { method: 'eroshare', label: 'eroshare', - pattern: new urlPattern('http(s)\\://eroshare.com/:id') + pattern: new urlPattern('http(s)\\://eroshare.com/:id(#)(:query)') }]; module.exports = function dissectLink(url) { diff --git a/src/methods/eroshare.js b/src/methods/eroshare.js index 972d1cc..d80c6e7 100644 --- a/src/methods/eroshare.js +++ b/src/methods/eroshare.js @@ -13,7 +13,7 @@ function eroshare(post) { return Promise.reject(`Unable to recover Eroshare video '${post.host.id}' :(`); }).then(res => { const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1)); - const extract = config.patterns.album.extractSingleItem && data.items.length === 1; + const extract = config.library.album.extractSingleItem && data.items.length === 1; return { album: extract ? null : { diff --git a/src/methods/imgurAlbum.js b/src/methods/imgurAlbum.js index 115cce0..5cd03f4 100644 --- a/src/methods/imgurAlbum.js +++ b/src/methods/imgurAlbum.js @@ -10,6 +10,10 @@ function imgurAlbum(post) { 'Authorization': `Client-ID ${config.methods.imgur.clientId}` } }).then(res => res.json()).then(res => { + if(!res.ok) { + throw new Error(`Could not fetch info for imgur album '${post.host.id}': ${res.data.error}`); + } + const extract = config.library.album.extractSingleItem && res.data.images.length === 1; if(extract) { @@ -37,7 +41,7 @@ function imgurAlbum(post) { })) }; }).catch(error => { - console.error(error); + return console.log('\x1b[31m%s\x1b[0m', error); }); }; diff --git a/src/methods/imgurImage.js b/src/methods/imgurImage.js index a27c8c9..95978fe 100644 --- a/src/methods/imgurImage.js +++ b/src/methods/imgurImage.js @@ -10,6 +10,10 @@ function imgurImage(post) { 'Authorization': `Client-ID ${config.methods.imgur.clientId}` } }).then(res => res.json()).then(res => { + if(!res.ok) { + throw new Error(`Could not fetch info for imgur image '${post.host.id}': ${res.data.error}`); + } + return { album: null, items: [{ @@ -23,7 +27,7 @@ function imgurImage(post) { }] }; }).catch(error => { - console.error(error); + return console.log('\x1b[31m%s\x1b[0m', error); }); };