From 50f8002d45cabe98a342426fe300ae9efc93eca3 Mon Sep 17 00:00:00 2001 From: Badri Sunderarajan Date: Fri, 8 May 2020 15:41:07 +0530 Subject: [PATCH] Make fetchMediumJSON's URL guessing more intelligent Now, it checks and processes the current query string instead of blindly tacking on a "?format=json" at the end. --- seance.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/seance.js b/seance.js index 636265d..61a40c7 100644 --- a/seance.js +++ b/seance.js @@ -336,9 +336,19 @@ class Seance { var text if (mediumUrl.match(/^http/i)) { - // add ?json attribute + // remove the anchors at the end mediumUrl = mediumUrl.replace(/#.*$/, '') - mediumUrl= `${mediumUrl}?format=json` + + // intelligently add ?json attribute + if (mediumUrl.indexOf('format=json') == -1) { + if (mediumUrl.indexOf('?') == 0) { + mediumUrl = `${mediumUrl}?format=json` + } else { + mediumUrl = `${mediumUrl}&format=json` + } + } + + // let's get it! const response = await fetch(mediumUrl) text = await response.text() } else if (fs.existsSync(mediumUrl)) {