From d051c6d71f2d2e24ca113f127ff7e0b143d0042a Mon Sep 17 00:00:00 2001 From: pep Date: Tue, 28 Jul 2020 08:49:23 +0000 Subject: fixed multiple files thing --- bucky/app/bucky.js | 3 +++ bucky/search/search.js | 1 - bucky/util/upload.js | 2 -- package.json | 3 ++- public/assets/js/lib/views/details/settings.js | 36 ++++++++++++++++++++++++++ views/partials/settings.ejs | 4 +++ 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 47026a8..f104e3b 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -514,6 +514,9 @@ var bucky = module.exports = { privacy: false, storage: process.env.S3_BUCKET, } + console.log(data) + //this library encodes things twice so have to do it yourself + url = `http://media.spermwhale.info/bucky/data/${data.thread}/${encodeURI(data.filename)}` req.body.comment = (req.body.comment.length) ? req.body.comment + "
\n" + url + "\n" + file.originalname : url+"\n"+file.originalname db.createFile(data).then(function(file){ resolve(file) diff --git a/bucky/search/search.js b/bucky/search/search.js index a4888ad..3bf882c 100644 --- a/bucky/search/search.js +++ b/bucky/search/search.js @@ -77,7 +77,6 @@ function search (query, start, limit, cb) { if (match.file) file_ids.push(match.file) return false }) - redisClient.quit() cb( { meta: { query: query, diff --git a/bucky/util/upload.js b/bucky/util/upload.js index e38fe30..dd82bf0 100644 --- a/bucky/util/upload.js +++ b/bucky/util/upload.js @@ -42,7 +42,6 @@ module.exports.put = function (opt) { } else { filename = uuid() + "." + extension; } - var remote_path = opt.dirname + filename if (types && ! extension) { @@ -75,7 +74,6 @@ module.exports.put = function (opt) { } var file_url = s3res.url || s3res.req.url - opt.success && opt.success(file_url) }).on('error', function(err, s3res){ console.error(err) diff --git a/package.json b/package.json index 558b162..0d9076b 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,9 @@ "node-uuid": "^1.4.8", "passport": "^0.3.0", "passport-local": "^1.0.0", - "redis": "^3.0.2", "pm2": "^3.5.1", + "redis": "^3.0.2", + "redis-redisearch": "^1.0.1", "serve-favicon": "^2.5.0", "sessionstore": "^1.3.5", "skipper": "^0.8.7", diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js index c2ff078..a027b12 100644 --- a/public/assets/js/lib/views/details/settings.js +++ b/public/assets/js/lib/views/details/settings.js @@ -17,6 +17,7 @@ var ThreadSettingsForm = FormView.extend({ "click [name=file_id]": "toggleFile", "click tr.file": "toggleFileRow", "click #move_files": "moveFiles", + "click .files_delete": "deleteFiles", }, action: "", @@ -307,6 +308,41 @@ var ThreadSettingsForm = FormView.extend({ alert('there was a problem moving the files...') }) }, + deleteFiles: function(){ + var inputs_checked = toArray(this.el.querySelectorAll("[name=file_id]:checked")) + var file_names = inputs_checked.map(input => input.parentElement.nextElementSibling.firstElementChild.innerHTML) + if (! inputs_checked.length) return + var msg = "Are you sure you want to delete these files? \n\n" + + file_names.join("\n") + var should_remove = confirm(msg) + if (should_remove) { + } + var promises = inputs_checked.map(node => { + return new Promise((resolve, reject) => { + $.ajax({ + method: "DELETE", + url: "/api/file/" + node.value, + headers: { "csrf-token": $("[name=_csrf]").attr("value") }, + data: JSON.stringify({ csrf: csrf() }), + dataType: "json", + success: function(data){ + console.log(data) + $(node).closest('.file').remove() + }, + error: function(){ + console.log('error deleting file', node.value) + reject() + } + }) + }) + }) + Promise.all(promises).then( () => { + window.location.href = '/details/' + thread_id + }).catch(() =>{ + console.error('whaaaaa') + alert('there was a problem deleting the files...') + }) + }, deleteThread: function(e){ var data = this.options.parent.data diff --git a/views/partials/settings.ejs b/views/partials/settings.ejs index 65fdf43..04eefcd 100644 --- a/views/partials/settings.ejs +++ b/views/partials/settings.ejs @@ -73,6 +73,10 @@

+
+
+
+
-- cgit v1.2.3-70-g09d2