Merge pull request '#131 filter users by submissions/comments' (#139) from juzz/teddit:main into main
Reviewed-on: https://codeberg.org/teddit/teddit/pulls/139
This commit is contained in:
commit
fa0f88a698
1
app.js
1
app.js
|
@ -11,7 +11,6 @@ const express = require('express')
|
|||
const cookieParser = require('cookie-parser')
|
||||
const r = require('redis')
|
||||
|
||||
|
||||
const redis = (() => {
|
||||
if (!config.redis_enabled) {
|
||||
// Stub Redis if disabled
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = function() {
|
||||
const config = require('../config');
|
||||
this.processJsonUser = function(json, parsed, after, before, user_preferences) {
|
||||
this.processJsonUser = function(json, parsed, after, before, user_preferences, kind, post_type) {
|
||||
return new Promise(resolve => {
|
||||
(async () => {
|
||||
if(!parsed) {
|
||||
|
@ -40,7 +40,10 @@ module.exports = function() {
|
|||
|
||||
let post_id = post.permalink.split('/').slice(-2)[0] + '/'
|
||||
let url = post.permalink.replace(post_id, '')
|
||||
|
||||
|
||||
if(type !== kind && kind)
|
||||
continue
|
||||
|
||||
if(post.over_18)
|
||||
if((config.nsfw_enabled === false && user_preferences.nsfw_enabled != 'true') || user_preferences.nsfw_enabled === 'false')
|
||||
continue
|
||||
|
@ -103,6 +106,7 @@ module.exports = function() {
|
|||
comment_karma: about.comment_karma,
|
||||
view_more_posts: view_more_posts,
|
||||
user_front: user_front,
|
||||
post_type: post_type,
|
||||
before: before,
|
||||
after: after,
|
||||
posts: posts
|
||||
|
|
29
routes.js
29
routes.js
|
@ -1005,7 +1005,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||
res.redirect(`/u/${req.params.user}`)
|
||||
})
|
||||
|
||||
app.get('/u/:user/:sort?', (req, res, next) => {
|
||||
app.get('/u/:user/:kind?/:sort?', (req, res, next) => {
|
||||
let user = req.params.user
|
||||
let after = req.query.after
|
||||
let before = req.query.before
|
||||
|
@ -1029,6 +1029,27 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||
if(before) {
|
||||
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':
|
||||
kind = 't1'
|
||||
break;
|
||||
case '/submitted':
|
||||
kind = 't3'
|
||||
break;
|
||||
default:
|
||||
post_type = ''
|
||||
kind = ''
|
||||
}
|
||||
} else {
|
||||
post_type = ''
|
||||
kind = ''
|
||||
}
|
||||
|
||||
let sortby = req.query.sort
|
||||
let past = req.query.t
|
||||
|
@ -1071,7 +1092,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||
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)
|
||||
let processed_json = await processJsonUser(json, false, after, before, req.cookies, kind, post_type)
|
||||
return res.render('user', {
|
||||
data: processed_json,
|
||||
sortby: sortby,
|
||||
|
@ -1096,7 +1117,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||
if(config.use_reddit_oauth)
|
||||
url = `https://oauth.reddit.com/user/${user}/overview?limit=26${d}&sort=${sortby}&t=${past}`
|
||||
else
|
||||
url = `https://reddit.com/user/${user}.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())
|
||||
.then(result => {
|
||||
if(result.status === 200) {
|
||||
|
@ -1112,7 +1133,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||
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)
|
||||
let processed_json = await processJsonUser(user_data, true, after, before, req.cookies, kind, post_type)
|
||||
return res.render('user', {
|
||||
data: processed_json,
|
||||
sortby: sortby,
|
||||
|
|
|
@ -23,13 +23,13 @@ html
|
|||
span sorted by: controversial
|
||||
ul
|
||||
li(class=!sortby || sortby == 'new' ? 'active' : '')
|
||||
a(href="/u/" + data.username) new
|
||||
a(href="/u/" + data.username + data.post_type) new
|
||||
li(class=sortby === 'hot' ? 'active' : '')
|
||||
a(href="/u/" + data.username + "?sort=hot") hot
|
||||
a(href="/u/" + data.username + data.post_type + "?sort=hot") hot
|
||||
li(class=sortby === 'top' ? 'active' : '')
|
||||
a(href="/u/" + data.username + "?sort=top&t=" + past + "") top
|
||||
a(href="/u/" + data.username + data.post_type + "?sort=top&t=" + past + "") top
|
||||
li(class=sortby === 'controversial' ? 'active' : '')
|
||||
a(href="/u/" + data.username + "?sort=controversial&t=" + past + "") controversial
|
||||
a(href="/u/" + data.username + data.post_type + "?sort=controversial&t=" + past + "") controversial
|
||||
if sortby === 'top' || sortby === 'controversial'
|
||||
details
|
||||
summary
|
||||
|
@ -132,7 +132,7 @@ html
|
|||
if data.before || data.after
|
||||
p view more:
|
||||
if data.before && !data.user_front
|
||||
a(href="/u/" + data.username + "?before=" + data.before + "") ‹ prev
|
||||
a(href="/u/" + data.username + data.post_type + "?before=" + data.before + "") ‹ prev
|
||||
if data.after
|
||||
a(href="/u/" + data.username + "?after=" + data.after + "") next ›
|
||||
a(href="/u/" + data.username + data.post_type + "?after=" + data.after + "") next ›
|
||||
include includes/footer.pug
|
||||
|
|
Loading…
Reference in New Issue