add fixes for #139

This commit is contained in:
teddit 2021-01-29 19:41:32 +01:00
parent fa0f88a698
commit d6e1a98187
3 changed files with 38 additions and 26 deletions

View File

@ -1009,6 +1009,8 @@ module.exports = (app, redis, fetch, RedditAPI) => {
let user = req.params.user
let after = req.query.after
let before = req.query.before
let post_type = req.params.kind
let kind = post_type
let user_data = {}
let api_req = req.query.api
let api_type = req.query.type
@ -1030,10 +1032,6 @@ module.exports = (app, redis, fetch, RedditAPI) => {
d = `&before=${before}`
}
let post_type = req.params.kind
let kind = post_type
if(!config.use_reddit_oauth) {
post_type = `/${post_type}`
switch(post_type) {
case '/comments':
@ -1046,10 +1044,6 @@ module.exports = (app, redis, fetch, RedditAPI) => {
post_type = ''
kind = ''
}
} else {
post_type = ''
kind = ''
}
let sortby = req.query.sort
let past = req.query.t
@ -1080,7 +1074,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
}
}
let key = `${user}:${after}:${before}:sort:${sortby}:past:${past}`
let key = `${user}:${after}:${before}:sort:${sortby}:past:${past}:post_type:${post_type}`
redis.get(key, (error, json) => {
if(error) {
console.error(`Error getting the user ${key} key from redis.`, error)
@ -1089,7 +1083,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
if(json) {
console.log(`Got user ${user} key from redis.`);
(async () => {
if(api_req) {
if(api_req) {
return handleTedditApiUser(json, req, res, 'redis', api_type, api_target, user, after, before)
} else {
let processed_json = await processJsonUser(json, false, after, before, req.cookies, kind, post_type)
@ -1114,10 +1108,14 @@ module.exports = (app, redis, fetch, RedditAPI) => {
.then(json => {
user_data.about = json
let url = ''
if(config.use_reddit_oauth)
url = `https://oauth.reddit.com/user/${user}/overview?limit=26${d}&sort=${sortby}&t=${past}`
else
if(config.use_reddit_oauth) {
let endpoint = '/overview'
if(post_type !== '')
endpoint = post_type
url = `https://oauth.reddit.com/user/${user}${post_type}?limit=26${d}&sort=${sortby}&t=${past}`
} else {
url = `https://reddit.com/user/${user}${post_type}.json?limit=26${d}&sort=${sortby}&t=${past}`
}
fetch(encodeURI(url), redditApiGETHeaders())
.then(result => {
if(result.status === 200) {
@ -1130,7 +1128,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
return res.render('index', { post: null, user_preferences: req.cookies })
} else {
(async () => {
if(api_req) {
if(api_req) {
return handleTedditApiUser(user_data, req, res, 'online', api_type, api_target, user, after, before)
} else {
let processed_json = await processJsonUser(user_data, true, after, before, req.cookies, kind, post_type)
@ -1165,7 +1163,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
})
} else {
if(result.status === 404) {
console.log('404  User not found')
console.log('404 User not found')
} else {
console.error(`Something went wrong while fetching data from Reddit. ${result.status} ${result.statusText}`)
console.error(config.reddit_api_error_text)

View File

@ -183,6 +183,9 @@ header a {
header a.main {
margin-left: 12px;
}
header h3.username {
margin: 0px 15px 0px 0px;
}
header .bottom {
float: left;
overflow: hidden;

View File

@ -10,6 +10,17 @@ html
p #{JSON.stringify(error_data)}
else
#user
header
.bottom
a(href="/u/" + data.username + "")
h3.username user: #{data.username}
ul.tabmenu
li(class=!data.post_type || data.post_type == '' ? 'active' : '')
a(href="/u/" + data.username) overview
li(class=data.post_type === '/comments' ? 'active' : '')
a(href="/u/" + data.username + "/comments") comments
li(class=data.post_type === '/submitted' ? 'active' : '')
a(href="/u/" + data.username + "/submitted") submitted
#links
details
summary