summaryrefslogtreecommitdiff
path: root/bucky/app
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/app')
-rw-r--r--bucky/app/api.js7
-rw-r--r--bucky/app/bucky.js45
-rw-r--r--bucky/app/pages.js8
3 files changed, 57 insertions, 3 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js
index 45dde3f..11ced51 100644
--- a/bucky/app/api.js
+++ b/bucky/app/api.js
@@ -37,9 +37,14 @@ function route (app){
app.get("/api/users",
middleware.ensureAuthenticated,
bucky.ensureUserlist,
+ bucky.ensureUserThreadCounts,
+ bucky.ensureUserFileCounts,
+ bucky.ensureUserCommentCounts,
+ bucky.ensureUserStatistics,
function(req, res) {
res.json({
- users: res.users
+ users: res.users,
+ userStats: res.userStats,
})
})
app.get("/api/profile/:username",
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 8ff0b15..74caa66 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -579,6 +579,51 @@ var bucky = module.exports = {
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 b007742..5d8551e 100644
--- a/bucky/app/pages.js
+++ b/bucky/app/pages.js
@@ -76,8 +76,12 @@ function route (app){
app.get("/users",
middleware.ensureAuthenticated,
function(req, res){
- res.render("pages/users", {
- })
+ res.render("pages/users", {})
+ })
+ app.get("/users/all",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/users", {})
})
app.get("/search/",