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
14
seance.js
14
seance.js
|
@ -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)) {
|
||||||
|
|
Loading…
Reference in a new issue