summaryrefslogtreecommitdiff
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
parent942a72123ecf7ed91cf3cba1124adc11a3615208 (diff)
deleting threads with comments and files and s3 files
-rw-r--r--bucky/app/bucky.js23
-rw-r--r--bucky/app/router.js2
-rw-r--r--bucky/db/index.js24
-rw-r--r--bucky/search/bdb.js2
-rw-r--r--bucky/search/lexicon.js4
-rw-r--r--package.json2
-rw-r--r--public/assets/js/lib/router.js2
7 files changed, 35 insertions, 24 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( () => {
diff --git a/bucky/app/router.js b/bucky/app/router.js
index 8eb9142..bac5e42 100644
--- a/bucky/app/router.js
+++ b/bucky/app/router.js
@@ -172,6 +172,8 @@ module.exports = function(app){
middleware.ensureAuthenticated,
bucky.ensureThread,
bucky.checkThreadPrivacy,
+ bucky.ensureCommentsForThread,
+ bucky.ensureFilesForThread,
bucky.destroyThread,
function(req, res){
res.sendStatus(200)
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 */
diff --git a/bucky/search/bdb.js b/bucky/search/bdb.js
index a7ced4a..6f1fd98 100644
--- a/bucky/search/bdb.js
+++ b/bucky/search/bdb.js
@@ -11,7 +11,7 @@ function db(fn){
fn = "./" + fn + ".db"
function exitHandler(options, err) {
- db.close()
+ if (db) db.close()
// if (options.cleanup) console.log('clean');
if (err) console.log(err.stack);
if (options.exit) process.exit();
diff --git a/bucky/search/lexicon.js b/bucky/search/lexicon.js
index 2cf0f21..a9729fd 100644
--- a/bucky/search/lexicon.js
+++ b/bucky/search/lexicon.js
@@ -4,6 +4,8 @@ var STOPWORDS = require('./stopwords')
var bdb = require('./bdb')
var db = require('../db')
+var search_db = bdb('search')
+
var lexicon = {}
var total = 0
@@ -100,7 +102,7 @@ function lexicon_store () {
put_total += 1
// if (put_total > 10) return
// console.log(term)
- bdb.put(term, serialized)
+ search_db.put(term, serialized)
})
}
function serialize_matches (matches) {
diff --git a/package.json b/package.json
index 0f5483c..653b542 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,8 @@
"description": "bucky",
"main": "index.js",
"scripts": {
+ "start": "node index",
+ "build:search": "node bucky/search/lexicon",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index a83437a..03c7bc8 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -85,7 +85,7 @@ var SiteRouter = Router.extend({
error404: function(){
$("content").hide()
$("#error_404").show()
- $("h1").html("error: page not found")
+ $("h1").html("404 not found")
$("body").removeClass("loading")
},