summaryrefslogtreecommitdiff
path: root/bucky/app/bucky.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-12 03:52:14 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-12 03:52:14 +0100
commitd4ece4ab1f461653c53bb56f23406c553ea78dd3 (patch)
tree6d86bcc41f08519b7478c5c1d5963b634047958e /bucky/app/bucky.js
parent942a72123ecf7ed91cf3cba1124adc11a3615208 (diff)
deleting threads with comments and files and s3 files
Diffstat (limited to 'bucky/app/bucky.js')
-rw-r--r--bucky/app/bucky.js23
1 files changed, 3 insertions, 20 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 15487e2..6ec76a0 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -161,13 +161,13 @@ var bucky = module.exports = {
ensureCommentsForThread: function (req, res, next){
db.getCommentsForThread(res.thread.get('id')).then(function(comments){
- res.comments = comments
+ res.comments = comments || []
next()
})
},
ensureFilesForThread: function (req, res, next){
db.getFilesForThread(res.thread.get('id')).then(function(files){
- res.files = files
+ res.files = files || []
next()
})
},
@@ -185,24 +185,7 @@ var bucky = module.exports = {
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 filePromises = db.destroyFiles(res.files)
var threadPromise = res.thread.destroy()
var promises = [ threadPromise ].concat(commentPromises).concat(filePromises)
Promise.all(promises).then( () => {