don't fetch sidebar for /r/all

This commit is contained in:
teddit 2020-12-08 18:54:30 +01:00
parent f5a070e6bd
commit c838f10d01
1 changed files with 37 additions and 33 deletions

View File

@ -23,41 +23,45 @@ module.exports = function() {
} }
resolve(obj) resolve(obj)
} else { } else {
fetch(encodeURI(`https://oauth.reddit.com/r/${subreddit}/about`), redditApiGETHeaders()) if(subreddit !== 'all') {
.then(result => { fetch(encodeURI(`https://oauth.reddit.com/r/${subreddit}/about`), redditApiGETHeaders())
if(result.status === 200) { .then(result => {
result.json() if(result.status === 200) {
.then(json => { result.json()
redis.setex(key, config.setexs.sidebar, JSON.stringify(json), (error) => { .then(json => {
if(error) { redis.setex(key, config.setexs.sidebar, JSON.stringify(json), (error) => {
console.error('Error setting the sidebar key to redis.', error) if(error) {
return res.render('index', { json: null, user_preferences: req.cookies }) console.error('Error setting the sidebar key to redis.', error)
} else { return res.render('index', { json: null, user_preferences: req.cookies })
console.log('Fetched the sidebar from reddit API.'); } else {
(async () => { console.log('Fetched the sidebar from reddit API.');
let obj = { (async () => {
title: json.data.title, let obj = {
public_description_html: json.data.public_description_html, title: json.data.title,
active_user_count: json.data.active_user_count, public_description_html: json.data.public_description_html,
subscribers: json.data.subscribers, active_user_count: json.data.active_user_count,
created_utc: json.data.created_utc, subscribers: json.data.subscribers,
over18: json.data.over18, created_utc: json.data.created_utc,
description_html: json.data.description_html over18: json.data.over18,
} description_html: json.data.description_html
resolve(obj) }
})() resolve(obj)
} })()
}
})
}) })
}) } 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}`) console.error(config.reddit_api_error_text)
console.error(config.reddit_api_error_text) resolve(null)
}
}).catch(error => {
console.error('Error fetching the sidebar.', error)
resolve(null)
})
} else {
resolve(null) resolve(null)
} }
}).catch(error => {
console.error('Error fetching the sidebar.', error)
resolve(null)
})
} }
}) })
} else { } else {