mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-06 20:05:40 +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) => {
|
||||
const url = `https://medium.com/${req.params.username}/latest?format=json`
|
||||
const j = request.jar()
|
||||
const requestWithCookies = request.defaults({ jar: j, json: true })
|
||||
const url = `https://medium.com/${req.params.username}/?format=json`
|
||||
|
||||
requestWithCookies(url, (error, response) => {
|
||||
request(url, (error, response) => {
|
||||
const prefix = '])}while(1);</x>'
|
||||
if (!response.body.includes(prefix)) {
|
||||
res.status(500).send({
|
||||
@ -24,7 +22,18 @@ app.get('/:username', (req, res) => {
|
||||
})
|
||||
}
|
||||
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 = []
|
||||
let holder = {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user