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.
This commit is contained in:
Badri Sunderarajan 2020-05-08 15:41:07 +05:30
parent 6496768956
commit 50f8002d45
1 changed files with 12 additions and 2 deletions

View File

@ -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)) {