1
0
mirror of https://github.com/oceanprotocol/webtasks synced 2025-01-08 13:02:53 +01:00

medium workaround

* closes https://github.com/oceanprotocol/site/issues/664
This commit is contained in:
Matthias Kretschmann 2019-11-11 14:17:50 +01:00
parent a38639c6cc
commit 3487b17311
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -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 = {}