summaryrefslogtreecommitdiff
path: root/bucky/app
diff options
context:
space:
mode:
authorpep <yes@peepee.me>2020-07-21 20:46:56 +0000
committerpep <yes@peepee.me>2020-07-21 20:46:56 +0000
commit97bee7fe1a48acb4c34e207863af56894c198151 (patch)
tree7a03bacd383319f2e4af70beb57ff0f9ae31b010 /bucky/app
parentd93c099733afff27fbf7c172a40eca87519d38b7 (diff)
parent8a3178339ad407ec85ef0cd014a6ad13bfb4cadd (diff)
attempt at merge
Diffstat (limited to 'bucky/app')
-rw-r--r--bucky/app/api.js25
-rw-r--r--bucky/app/bucky.js64
-rw-r--r--bucky/app/pages.js11
3 files changed, 100 insertions, 0 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js
index 75cdbd7..d2472c3 100644
--- a/bucky/app/api.js
+++ b/bucky/app/api.js
@@ -34,6 +34,19 @@ function route (app){
function(req, res){
res.json(util.sanitizeUser(res.user))
})
+ app.get("/api/users",
+ middleware.ensureAuthenticated,
+ bucky.ensureUserlist,
+ bucky.ensureUserThreadCounts,
+ bucky.ensureUserFileCounts,
+ bucky.ensureUserCommentCounts,
+ bucky.ensureUserStatistics,
+ function(req, res) {
+ res.json({
+ users: res.users,
+ userStats: res.userStats,
+ })
+ })
app.get("/api/profile/:username",
middleware.ensureAuthenticated,
bucky.ensureUser,
@@ -153,6 +166,16 @@ function route (app){
function(req, res){
res.send({ status: 'ok' })
})
+ app.get("/api/thread/:id/bury",
+ middleware.ensureAuthenticated,
+ bucky.ensureThread,
+ privacy.checkThreadPrivacy,
+ bucky.buryThread,
+ function(req, res){
+ res.json({
+ thread: res.thread,
+ })
+ })
/* comments */
@@ -259,9 +282,11 @@ function route (app){
middleware.ensureAuthenticated,
bucky.ensureKeywords,
bucky.ensureThreadGroups,
+ bucky.ensureLatestKeywordThreads,
function(req, res){
res.json({
keywords: res.keywords,
+ threads: res.threads,
threadGroups: res.threadGroups,
})
})
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 8d9839f..ab153f9 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -227,6 +227,10 @@ var bucky = module.exports = {
next()
})
},
+ buryThread: function (req, res, next){
+ res.thread.set('lastmodified', util.now() - (14 * 86400))
+ res.thread.save().then( () => next() )
+ },
// ensureInterestedUsers: function(req, res, next){
// // given a thread, find people who might be interested in it
// // - other people who have been in threads with you
@@ -296,6 +300,12 @@ var bucky = module.exports = {
next()
})
},
+ ensureLatestKeywordThreads: function (req, res, next){
+ db.getLatestKeywordThreads().then(function(threads){
+ res.threads = threads
+ next()
+ })
+ },
ensureThreadGroups: function (req, res, next){
db.getThreadGroups().then(function(threadGroups){
res.threadGroups = threadGroups
@@ -571,6 +581,60 @@ var bucky = module.exports = {
}
})
},
+ ensureUserlist: function (req, res, next){
+ db.getUsers().then(function(users){
+ if (! users) {
+ return res.sendStatus(404)
+ }
+ res.users = users
+ next()
+ })
+ },
+ ensureUserThreadCounts: function (req, res, next) {
+ db.getUserThreadCounts().then(function(counts){
+ if (!counts) {
+ return res.sendStatus(404)
+ }
+ res.threadCounts = counts
+ next()
+ })
+ },
+ ensureUserCommentCounts: function (req, res, next) {
+ db.getUserCommentCounts().then(function(counts){
+ if (!counts) {
+ return res.sendStatus(404)
+ }
+ res.commentCounts = counts
+ next()
+ })
+ },
+ ensureUserFileCounts: function (req, res, next) {
+ db.getUserFileCounts().then(function(counts){
+ if (!counts) {
+ return res.sendStatus(404)
+ }
+ res.fileCounts = counts
+ next()
+ })
+ },
+ ensureUserStatistics: function (req, res, next) {
+ var stats = {}
+ res.threadCounts.forEach(function(user){
+ stats[user.username] = stats[user.username] || {}
+ stats[user.username].threads = user.count
+ })
+ res.commentCounts.forEach(function(user){
+ stats[user.username] = stats[user.username] || {}
+ stats[user.username].comments = user.count
+ })
+ res.fileCounts.forEach(function(user){
+ stats[user.username] = stats[user.username] || {}
+ stats[user.username].files = user.count
+ stats[user.username].fileSize = user.size
+ })
+ res.userStats = stats
+ next()
+ },
sanitizeUser: function(req, res, next) {
res.user = util.sanitizeUser(res.user)
next()
diff --git a/bucky/app/pages.js b/bucky/app/pages.js
index 7f666be..5d8551e 100644
--- a/bucky/app/pages.js
+++ b/bucky/app/pages.js
@@ -73,6 +73,17 @@ function route (app){
res.render("pages/profile_form", {title: "edit your profile"})
})
+ app.get("/users",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/users", {})
+ })
+ app.get("/users/all",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/users", {})
+ })
+
app.get("/search/",
middleware.ensureAuthenticated,
function(req, res){