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:
parent
6496768956
commit
50f8002d45
1 changed files with 12 additions and 2 deletions
12
seance.js
12
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(/#.*$/, '')
|
||||
|
||||
// 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)) {
|
||||
|
|
Loading…
Reference in a new issue