mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-26 09:09:27 +01:00
check that morechildren data has .things
This commit is contained in:
parent
1d79e23b70
commit
9531e5527d
28
routes.js
28
routes.js
@ -730,18 +730,26 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
if(result.status === 200) {
|
if(result.status === 200) {
|
||||||
result.json()
|
result.json()
|
||||||
.then(json => {
|
.then(json => {
|
||||||
let comments = json.json.data.things
|
if(json.json.data) {
|
||||||
redis.setex(key, config.setexs.posts, JSON.stringify(comments), (error) => {
|
if(json.json.data.things) {
|
||||||
if(error) {
|
let comments = json.json.data.things
|
||||||
console.error(`Error setting the ${key} key to redis.`, error)
|
redis.setex(key, config.setexs.posts, JSON.stringify(comments), (error) => {
|
||||||
return res.render('post', { post: null, user_preferences: req.cookies })
|
if(error) {
|
||||||
|
console.error(`Error setting the ${key} key to redis.`, error)
|
||||||
|
return res.render('post', { post: null, user_preferences: req.cookies })
|
||||||
|
} else {
|
||||||
|
redis.setex(`morechildren_ids:${post_url}`, config.setexs.posts, JSON.stringify(all_ids))
|
||||||
|
console.log(`Fetched the JSON from reddit API (endpoint "morechildren") with url: ${url}.`)
|
||||||
|
console.log(`Redirecting to ${post_url} with cursor...`)
|
||||||
|
return res.redirect(`${post_url}?cursor=${page}&page=${page}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
redis.setex(`morechildren_ids:${post_url}`, config.setexs.posts, JSON.stringify(all_ids))
|
return res.redirect(post_url)
|
||||||
console.log(`Fetched the JSON from reddit API (endpoint "morechildren") with url: ${url}.`)
|
|
||||||
console.log(`Redirecting to ${post_url} with cursor...`)
|
|
||||||
return res.redirect(`${post_url}?cursor=${page}&page=${page}`)
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
|
return res.redirect(post_url)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.error(`Something went wrong while fetching data from reddit API. ${result.status} – ${result.statusText}`)
|
console.error(`Something went wrong while fetching data from reddit API. ${result.status} – ${result.statusText}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user