summaryrefslogtreecommitdiff
path: root/bucky/db/index.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/db/index.js
parent942a72123ecf7ed91cf3cba1124adc11a3615208 (diff)
deleting threads with comments and files and s3 files
Diffstat (limited to 'bucky/db/index.js')
-rw-r--r--bucky/db/index.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js
index 0ce6e5f..9e01e9b 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -3,7 +3,7 @@ var db = module.exports
var connection = require("./bookshelf")
var bookshelf = connection.bookshelf
var knex = connection.knex
-
+var upload = require('../util/upload')
/* MODELS */
@@ -103,6 +103,28 @@ db.createFile = function(data){
}
db.destroyFile = function(id){
}
+db.destroyFiles = function(files){
+ var s3client = upload.client()
+ var rmPromises = files.map((file) => {
+ return new Promise ((resolve, reject) => {
+ var thread_id = file.get('thread')
+ var filename = file.get('filename')
+ if (! thread_id || ! filename) {
+ return resolve()
+ }
+ var filePath = '/bucky/data/' + thread_id + '/' + filename
+ console.log(filePath)
+ s3client.deleteFile(filePath, function(err, res){
+ // check `err`, then do `res.pipe(..)` or `res.resume()` or whatever.
+ resolve()
+ })
+ })
+ })
+ var filePromises = files.map((file) => {
+ return file.destroy()
+ })
+ return Promise.all(rmPromises.join(filePromises))
+}
/* COMMENTS */