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

View file

@ -336,9 +336,19 @@ class Seance {
var text var text
if (mediumUrl.match(/^http/i)) { if (mediumUrl.match(/^http/i)) {
// add ?json attribute // remove the anchors at the end
mediumUrl = mediumUrl.replace(/#.*$/, '') 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) const response = await fetch(mediumUrl)
text = await response.text() text = await response.text()
} else if (fs.existsSync(mediumUrl)) { } else if (fs.existsSync(mediumUrl)) {