summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-15 05:36:50 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-15 05:36:50 +0100
commit7ad469291c015b33a2d20587db26b9621ed82d00 (patch)
tree83e2a56822033a638d03ff7ddf4bfee3181631e6 /bucky
parentcc585396a85e3107bb7b4298098b84b738919c8f (diff)
sort file list by name or date, updates audio player
Diffstat (limited to 'bucky')
-rw-r--r--bucky/app/bucky.js59
-rw-r--r--bucky/app/router.js29
-rw-r--r--bucky/db/index.js15
3 files changed, 64 insertions, 39 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index ec0ab8c..25de991 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -184,6 +184,8 @@ var bucky = module.exports = {
return res.sendStatus(500)
}
var keyword = util.sanitize(req.body.keyword || "")
+ var privacy = parseInt(req.body.privacy) || 0
+ var allowed = util.sanitize(req.body.allowed || "")
var settings
if (typeof req.body.settings === 'object') {
try {
@@ -194,29 +196,48 @@ var bucky = module.exports = {
if (! settings) {
return res.sendStatus(500)
}
+console.log(privacy)
res.thread.set('title', title)
res.thread.set('keyword', keyword)
res.thread.set('color', util.sanitize(req.body.color || 'blue'))
res.thread.set('revision', res.thread.get('revision')+1)
res.thread.set('settings', settings)
- 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
- // - other people who have posted on the keyword
- // for now though, just show the last 20 people who have logged in..
- db.getLastlog(21).then( (users) => {
- res.interestedUsers = users
- next()
- }).catch( () => {
- res.interestedUsers = []
+ res.thread.set('privacy', privacy)
+ res.thread.set('allowed', allowed)
+ res.thread.save()
+ .then( () => next() )
+ .catch(err => {
+ console.error(err)
next()
})
},
- ensureThreadUsers: function(req, res, next) {
- db.getThreadUsers(res.thread.get('id')).then(thread_users => {
- res.thread_users = thread_users
+// 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
+// // - other people who have posted on the keyword
+// // for now though, just show the last 20 people who have logged in..
+// db.getLastlog(21).then( (users) => {
+// res.interestedUsers = users
+// next()
+// }).catch( () => {
+// res.interestedUsers = []
+// next()
+// })
+// },
+// ensureThreadUsers: function(req, res, next) {
+// db.getThreadUsers(res.thread.get('id')).then(thread_users => {
+// res.thread_users = thread_users
+// next()
+// })
+// },
+ checkUsernames: function(req, res, next) {
+ if (! req.body.usernames) return res.sendStatus(500)
+ db.checkUsernames(req.body.usernames).then( (users) => {
+ res.usernames = users.map(user => user.username)
+ next()
+ }).catch((err) => {
+ console.log(err)
+ res.usernames = []
next()
})
},
@@ -370,6 +391,7 @@ var bucky = module.exports = {
reject(err)
},
success: function(url){
+ console.log("file >", url)
var data = {
thread: res.thread.get('id'),
username: req.user.get('username'),
@@ -436,7 +458,7 @@ var bucky = module.exports = {
res.sendStatus({ error: 'Problem uploading avatar.' })
},
success: function(url){
- console.log(">", url)
+ console.log("avatar >", url)
res.user.set('avatar', url)
next()
}
@@ -461,7 +483,7 @@ var bucky = module.exports = {
next()
},
checkThreadPrivacy: function(req, res, next) {
- if (res.thread.checkPrivacy(req.user)) {
+ if (! res.thread.checkPrivacy(req.user)) {
return res.sendStatus(500)
}
next()
@@ -479,10 +501,11 @@ var bucky = module.exports = {
}
next()
},
- checkThreadsPrivacy: function(req, res, next) {
+ filterPrivateThreads: function(req, res, next) {
res.threads = res.threads.filter(thread => {
return thread.checkPrivacy(req.user)
})
+ next()
},
/* MAIL */
diff --git a/bucky/app/router.js b/bucky/app/router.js
index 106c65e..e24253a 100644
--- a/bucky/app/router.js
+++ b/bucky/app/router.js
@@ -76,8 +76,7 @@ module.exports = function(app){
bucky.sanitizeUser,
function(req, res) {
res.json(res.user)
- }
- )
+ })
app.post("/api/user/:username",
middleware.ensureAuthenticated,
bucky.ensureUser,
@@ -90,6 +89,13 @@ module.exports = function(app){
function(req, res){
res.json(util.sanitizeUser(res.user))
})
+ app.put("/api/checkUsernames",
+ middleware.ensureAuthenticated,
+ bucky.checkUsernames,
+ function(req, res){
+ res.send({ usernames: res.usernames })
+ })
+
/* threads */
@@ -97,7 +103,7 @@ module.exports = function(app){
bucky.ensureLastlog,
middleware.ensureAuthenticated,
bucky.ensureLatestThreads,
- bucky.ensureThreadsPrivacy,
+ bucky.filterPrivateThreads,
bucky.ensureCommentCountsForThreads,
bucky.ensureFileCountsForThreads,
bucky.ensureKeywordsForThreads,
@@ -114,7 +120,7 @@ module.exports = function(app){
bucky.ensureLastlog,
middleware.ensureAuthenticated,
bucky.ensureThreadsForKeyword,
- bucky.ensureThreadsPrivacy,
+ bucky.filterPrivateThreads,
bucky.ensureCommentCountsForThreads,
bucky.ensureFileCountsForThreads,
bucky.ensureKeywordsForThreads,
@@ -127,22 +133,11 @@ module.exports = function(app){
lastlog: res.lastlog,
})
})
- // app.get("/api/thread/:id/interested",
- // middleware.ensureAuthenticated,
- // bucky.ensureThread,
- // bucky.ensureThreadPrivacy,
- // bucky.ensureInterestedUsers,
- // // bucky.ensureThreadUsers,
- // function(req, res){
- // res.json({
- // interestedUsers: res.interestedUsers,
- // })
- // })
app.get("/api/thread/:id",
middleware.ensureAuthenticated,
bucky.ensureThread,
+ bucky.checkThreadPrivacy,
bucky.bumpViewCount,
- bucky.ensureThreadPrivacy,
bucky.ensureKeywordForThread,
bucky.ensureCommentsForThread,
bucky.ensureFilesForThread,
@@ -152,7 +147,6 @@ module.exports = function(app){
function(req, res){
res.json({
thread: res.thread,
- thread_users: res.thread,
comments: res.comments,
files: res.files,
keyword: res.keyword,
@@ -261,6 +255,7 @@ module.exports = function(app){
middleware.ensureAuthenticated,
bucky.ensureKeyword,
bucky.ensureThreadsForKeyword,
+ bucky.filterPrivateThreads,
bucky.ensureCommentCountsForThreads,
bucky.ensureFileCountsForThreads,
bucky.ensureKeywordsForThreads,
diff --git a/bucky/db/index.js b/bucky/db/index.js
index 652f723..f92ba2f 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -18,8 +18,9 @@ var Thread = db.Thread = bookshelf.Model.extend({
if (this.get('privacy') === 0) return true
let username = user.get('username')
if (this.get('username') === username) return true
- let allowed = this.get('allowed').split(',')
- if (allowed.findIndex(username) !== -1) return true
+ let allowed = (this.get('allowed') || '').split(',')
+ if (allowed.indexOf(username) !== -1) return true
+ return false
}
})
var ThreadUser = db.ThreadUser = bookshelf.Model.extend({
@@ -65,13 +66,19 @@ db.getUsersById = function(ids){
return User.where("id", "in", ids).fetchAll()
}
db.getUsernamesById = function(ids){
- return User.column("id").column("username").where("id", "in", ids).fetchAll()
+ return knex.column("id").column("username")
+ .select().from('users').where("id", "in", ids)
+}
+db.checkUsernames = function(usernames){
+ return knex.column("username")
+ .select().distinct().from('users').where("username", "in", usernames)
}
db.getUserByUsername = function(username) {
return new User({'username': username}).fetch()
}
db.getLastlog = function(limit){
- return knex.column('id').column('username').column('lastseen').select().from('users').orderBy('lastseen', 'desc').limit(limit || 10)
+ return knex.column('id').column('username').column('lastseen')
+ .select().from('users').orderBy('lastseen', 'desc').limit(limit || 10)
}
/* THREADS */