mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-22 14:59:26 +01:00
add fixes for #139
This commit is contained in:
parent
fa0f88a698
commit
d6e1a98187
28
routes.js
28
routes.js
@ -1009,6 +1009,8 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
let user = req.params.user
|
let user = req.params.user
|
||||||
let after = req.query.after
|
let after = req.query.after
|
||||||
let before = req.query.before
|
let before = req.query.before
|
||||||
|
let post_type = req.params.kind
|
||||||
|
let kind = post_type
|
||||||
let user_data = {}
|
let user_data = {}
|
||||||
let api_req = req.query.api
|
let api_req = req.query.api
|
||||||
let api_type = req.query.type
|
let api_type = req.query.type
|
||||||
@ -1030,10 +1032,6 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
d = `&before=${before}`
|
d = `&before=${before}`
|
||||||
}
|
}
|
||||||
|
|
||||||
let post_type = req.params.kind
|
|
||||||
let kind = post_type
|
|
||||||
|
|
||||||
if(!config.use_reddit_oauth) {
|
|
||||||
post_type = `/${post_type}`
|
post_type = `/${post_type}`
|
||||||
switch(post_type) {
|
switch(post_type) {
|
||||||
case '/comments':
|
case '/comments':
|
||||||
@ -1046,10 +1044,6 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
post_type = ''
|
post_type = ''
|
||||||
kind = ''
|
kind = ''
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
post_type = ''
|
|
||||||
kind = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
let sortby = req.query.sort
|
let sortby = req.query.sort
|
||||||
let past = req.query.t
|
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) => {
|
redis.get(key, (error, json) => {
|
||||||
if(error) {
|
if(error) {
|
||||||
console.error(`Error getting the user ${key} key from redis.`, error)
|
console.error(`Error getting the user ${key} key from redis.`, error)
|
||||||
@ -1089,7 +1083,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
if(json) {
|
if(json) {
|
||||||
console.log(`Got user ${user} key from redis.`);
|
console.log(`Got user ${user} key from redis.`);
|
||||||
(async () => {
|
(async () => {
|
||||||
if(api_req) {
|
if(api_req) {
|
||||||
return handleTedditApiUser(json, req, res, 'redis', api_type, api_target, user, after, before)
|
return handleTedditApiUser(json, req, res, 'redis', api_type, api_target, user, after, before)
|
||||||
} else {
|
} else {
|
||||||
let processed_json = await processJsonUser(json, false, after, before, req.cookies, kind, post_type)
|
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 => {
|
.then(json => {
|
||||||
user_data.about = json
|
user_data.about = json
|
||||||
let url = ''
|
let url = ''
|
||||||
if(config.use_reddit_oauth)
|
if(config.use_reddit_oauth) {
|
||||||
url = `https://oauth.reddit.com/user/${user}/overview?limit=26${d}&sort=${sortby}&t=${past}`
|
let endpoint = '/overview'
|
||||||
else
|
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}`
|
url = `https://reddit.com/user/${user}${post_type}.json?limit=26${d}&sort=${sortby}&t=${past}`
|
||||||
|
}
|
||||||
fetch(encodeURI(url), redditApiGETHeaders())
|
fetch(encodeURI(url), redditApiGETHeaders())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if(result.status === 200) {
|
if(result.status === 200) {
|
||||||
@ -1130,7 +1128,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
return res.render('index', { post: null, user_preferences: req.cookies })
|
return res.render('index', { post: null, user_preferences: req.cookies })
|
||||||
} else {
|
} else {
|
||||||
(async () => {
|
(async () => {
|
||||||
if(api_req) {
|
if(api_req) {
|
||||||
return handleTedditApiUser(user_data, req, res, 'online', api_type, api_target, user, after, before)
|
return handleTedditApiUser(user_data, req, res, 'online', api_type, api_target, user, after, before)
|
||||||
} else {
|
} else {
|
||||||
let processed_json = await processJsonUser(user_data, true, after, before, req.cookies, kind, post_type)
|
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 {
|
} else {
|
||||||
if(result.status === 404) {
|
if(result.status === 404) {
|
||||||
console.log('404 – User not found')
|
console.log('404 – User not found')
|
||||||
} else {
|
} else {
|
||||||
console.error(`Something went wrong while fetching data from Reddit. ${result.status} – ${result.statusText}`)
|
console.error(`Something went wrong while fetching data from Reddit. ${result.status} – ${result.statusText}`)
|
||||||
console.error(config.reddit_api_error_text)
|
console.error(config.reddit_api_error_text)
|
||||||
|
@ -183,6 +183,9 @@ header a {
|
|||||||
header a.main {
|
header a.main {
|
||||||
margin-left: 12px;
|
margin-left: 12px;
|
||||||
}
|
}
|
||||||
|
header h3.username {
|
||||||
|
margin: 0px 15px 0px 0px;
|
||||||
|
}
|
||||||
header .bottom {
|
header .bottom {
|
||||||
float: left;
|
float: left;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -10,6 +10,17 @@ html
|
|||||||
p #{JSON.stringify(error_data)}
|
p #{JSON.stringify(error_data)}
|
||||||
else
|
else
|
||||||
#user
|
#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
|
#links
|
||||||
details
|
details
|
||||||
summary
|
summary
|
||||||
|
Loading…
Reference in New Issue
Block a user