summaryrefslogtreecommitdiff
path: root/bucky/app/bucky.js
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/app/bucky.js')
-rw-r--r--bucky/app/bucky.js53
1 files changed, 46 insertions, 7 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 9d8d0a7..15487e2 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -180,7 +180,38 @@ var bucky = module.exports = {
res.thread.set('lastmodified', util.now())
res.thread.save().then( () => next() )
},
-
+ destroyThread: function (req, res, next) {
+ console.log(">>> destroying thread", res.thread.get('id'))
+ var commentPromises = res.comments.map((comment) => {
+ return comment.destroy()
+ })
+ var s3client = upload.client()
+ var rmPromises = res.files.map((file) => {
+ return new Promise ((resolve, reject) => {
+ var thread_id = file.get('thread')
+ if (! thread_id || ! file.filename) {
+ console.log("weird malformed file?", file)
+ return resolve()
+ }
+ var filePath = '/bucky/' + thread_id + '/' + file.get('filename')
+ s3client.deleteFile(filePath, function(err, res){
+ // check `err`, then do `res.pipe(..)` or `res.resume()` or whatever.
+ resolve()
+ })
+ })
+ })
+ var filePromises = res.files.map((file) => {
+ return file.destroy()
+ })
+ var threadPromise = res.thread.destroy()
+ var promises = [ threadPromise ].concat(commentPromises).concat(filePromises)
+ Promise.all(promises).then( () => {
+ next()
+ }).catch( () => {
+ res.sendStatus(500)
+ })
+ },
+
/* KEYWORDS */
ensureKeyword: function (req, res, next){
@@ -248,12 +279,6 @@ var bucky = module.exports = {
}
})
},
- checkCommentPrivacy: function(req, res, next) {
- if (req.user.get('ulevel') !== 3 && req.user.get('username') !== res.comment.get('username')) {
- return res.sendStatus(500)
- }
- next()
- },
createOptionalComment: function(req, res, next){
if (! req.body.comment || ! req.body.comment.length) {
return next()
@@ -363,6 +388,20 @@ var bucky = module.exports = {
})
},
+ /* PRIVACY */
+ checkThreadPrivacy: function(req, res, next) {
+ if (req.user.get('ulevel') !== 3 && req.user.get('username') !== res.thread.get('username')) {
+ return res.sendStatus(500)
+ }
+ next()
+ },
+ checkCommentPrivacy: function(req, res, next) {
+ if (req.user.get('ulevel') !== 3 && req.user.get('username') !== res.comment.get('username')) {
+ return res.sendStatus(500)
+ }
+ next()
+ },
+
/* MAIL */
ensureMailboxes: function (req, res, next){