summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
Diffstat (limited to 'bucky')
-rw-r--r--bucky/app/bucky.js53
-rw-r--r--bucky/app/router.js8
-rw-r--r--bucky/search/middleware.js2
-rw-r--r--bucky/util/upload.js4
4 files changed, 55 insertions, 12 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){
diff --git a/bucky/app/router.js b/bucky/app/router.js
index fc5c7ea..8eb9142 100644
--- a/bucky/app/router.js
+++ b/bucky/app/router.js
@@ -166,15 +166,15 @@ module.exports = function(app){
bucky.checkCommentPrivacy,
bucky.destroyComment,
function(req, res){
- res.send(200)
+ res.sendStatus(200)
})
app.delete("/api/thread/:id",
middleware.ensureAuthenticated,
bucky.ensureThread,
-// bucky.destroyThread,
+ bucky.checkThreadPrivacy,
+ bucky.destroyThread,
function(req, res){
- // delete a thread
- res.send(200)
+ res.sendStatus(200)
})
app.get("/search/",
diff --git a/bucky/search/middleware.js b/bucky/search/middleware.js
index 32e3321..314afbc 100644
--- a/bucky/search/middleware.js
+++ b/bucky/search/middleware.js
@@ -94,7 +94,7 @@ module.exports = {
}
return m
})
- res.send({
+ res.json({
meta: res.search.meta,
results: results,
})
diff --git a/bucky/util/upload.js b/bucky/util/upload.js
index 242acf0..a1810a4 100644
--- a/bucky/util/upload.js
+++ b/bucky/util/upload.js
@@ -22,6 +22,10 @@ module.exports.init = function (opt){
})
}
+module.exports.client = function(){
+ return s3
+}
+
module.exports.put = function (opt) {
var filename
var err