131 post kind on user page without oauth
This commit is contained in:
parent
1f296ec3aa
commit
7555a3c75e
1
app.js
1
app.js
|
@ -11,7 +11,6 @@ const express = require('express')
|
||||||
const cookieParser = require('cookie-parser')
|
const cookieParser = require('cookie-parser')
|
||||||
const r = require('redis')
|
const r = require('redis')
|
||||||
|
|
||||||
|
|
||||||
const redis = (() => {
|
const redis = (() => {
|
||||||
if (!config.redis_enabled) {
|
if (!config.redis_enabled) {
|
||||||
// Stub Redis if disabled
|
// Stub Redis if disabled
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = function() {
|
module.exports = function() {
|
||||||
const config = require('../config');
|
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 => {
|
return new Promise(resolve => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if(!parsed) {
|
if(!parsed) {
|
||||||
|
@ -41,6 +41,9 @@ module.exports = function() {
|
||||||
let post_id = post.permalink.split('/').slice(-2)[0] + '/'
|
let post_id = post.permalink.split('/').slice(-2)[0] + '/'
|
||||||
let url = post.permalink.replace(post_id, '')
|
let url = post.permalink.replace(post_id, '')
|
||||||
|
|
||||||
|
if(type !== kind && kind)
|
||||||
|
continue
|
||||||
|
|
||||||
if(post.over_18)
|
if(post.over_18)
|
||||||
if((config.nsfw_enabled === false && user_preferences.nsfw_enabled != 'true') || user_preferences.nsfw_enabled === 'false')
|
if((config.nsfw_enabled === false && user_preferences.nsfw_enabled != 'true') || user_preferences.nsfw_enabled === 'false')
|
||||||
continue
|
continue
|
||||||
|
@ -103,6 +106,7 @@ module.exports = function() {
|
||||||
comment_karma: about.comment_karma,
|
comment_karma: about.comment_karma,
|
||||||
view_more_posts: view_more_posts,
|
view_more_posts: view_more_posts,
|
||||||
user_front: user_front,
|
user_front: user_front,
|
||||||
|
post_type: post_type,
|
||||||
before: before,
|
before: before,
|
||||||
after: after,
|
after: after,
|
||||||
posts: posts
|
posts: posts
|
||||||
|
|
29
routes.js
29
routes.js
|
@ -1005,7 +1005,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||||
res.redirect(`/u/${req.params.user}`)
|
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 user = req.params.user
|
||||||
let after = req.query.after
|
let after = req.query.after
|
||||||
let before = req.query.before
|
let before = req.query.before
|
||||||
|
@ -1030,6 +1030,27 @@ 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}`
|
||||||
|
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 sortby = req.query.sort
|
||||||
let past = req.query.t
|
let past = req.query.t
|
||||||
|
|
||||||
|
@ -1071,7 +1092,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||||
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)
|
let processed_json = await processJsonUser(json, false, after, before, req.cookies, kind, post_type)
|
||||||
return res.render('user', {
|
return res.render('user', {
|
||||||
data: processed_json,
|
data: processed_json,
|
||||||
sortby: sortby,
|
sortby: sortby,
|
||||||
|
@ -1096,7 +1117,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||||
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}`
|
url = `https://oauth.reddit.com/user/${user}/overview?limit=26${d}&sort=${sortby}&t=${past}`
|
||||||
else
|
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())
|
fetch(encodeURI(url), redditApiGETHeaders())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if(result.status === 200) {
|
if(result.status === 200) {
|
||||||
|
@ -1112,7 +1133,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||||
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)
|
let processed_json = await processJsonUser(user_data, true, after, before, req.cookies, kind, post_type)
|
||||||
return res.render('user', {
|
return res.render('user', {
|
||||||
data: processed_json,
|
data: processed_json,
|
||||||
sortby: sortby,
|
sortby: sortby,
|
||||||
|
|
|
@ -23,13 +23,13 @@ html
|
||||||
span sorted by: controversial
|
span sorted by: controversial
|
||||||
ul
|
ul
|
||||||
li(class=!sortby || sortby == 'new' ? 'active' : '')
|
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' : '')
|
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' : '')
|
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' : '')
|
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'
|
if sortby === 'top' || sortby === 'controversial'
|
||||||
details
|
details
|
||||||
summary
|
summary
|
||||||
|
@ -132,7 +132,7 @@ html
|
||||||
if data.before || data.after
|
if data.before || data.after
|
||||||
p view more:
|
p view more:
|
||||||
if data.before && !data.user_front
|
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
|
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
|
include includes/footer.pug
|
||||||
|
|
Loading…
Reference in New Issue