mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-07 20:35:30 +01:00
medium workaround
* closes https://github.com/oceanprotocol/site/issues/664
This commit is contained in:
parent
a38639c6cc
commit
3487b17311
@ -11,11 +11,9 @@ app.get('/', (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.get('/:username', (req, res) => {
|
app.get('/:username', (req, res) => {
|
||||||
const url = `https://medium.com/${req.params.username}/latest?format=json`
|
const url = `https://medium.com/${req.params.username}/?format=json`
|
||||||
const j = request.jar()
|
|
||||||
const requestWithCookies = request.defaults({ jar: j, json: true })
|
|
||||||
|
|
||||||
requestWithCookies(url, (error, response) => {
|
request(url, (error, response) => {
|
||||||
const prefix = '])}while(1);</x>'
|
const prefix = '])}while(1);</x>'
|
||||||
if (!response.body.includes(prefix)) {
|
if (!response.body.includes(prefix)) {
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
@ -24,7 +22,18 @@ app.get('/:username', (req, res) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
const json = JSON.parse(response.body.replace(prefix, ''))
|
const json = JSON.parse(response.body.replace(prefix, ''))
|
||||||
const { posts } = json.payload
|
|
||||||
|
let posts
|
||||||
|
|
||||||
|
if (json.payload.posts) {
|
||||||
|
posts = json.payload.posts
|
||||||
|
}
|
||||||
|
if (json.payload.references.Post) {
|
||||||
|
posts = Object.keys(json.payload.references.Post).map(
|
||||||
|
key => json.payload.references.Post[key]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const parsedPosts = []
|
const parsedPosts = []
|
||||||
let holder = {}
|
let holder = {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user