summaryrefslogtreecommitdiff
path: root/bucky/app/bucky.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-15 11:24:00 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-15 11:24:00 +0100
commit148bdaec5aaf66b885d7070894b81dfd76df2d5c (patch)
treed60aec3ac20db83fbda10632c92e0e3901fbdb52 /bucky/app/bucky.js
parent6c601a35b1d79bfe5b53c3c6177420c9d90fbba9 (diff)
delete files
Diffstat (limited to 'bucky/app/bucky.js')
-rw-r--r--bucky/app/bucky.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 295a813..dbb980d 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -371,7 +371,23 @@ var bucky = module.exports = {
},
/* FILES */
-
+
+ ensureFile: function (req, res, next){
+ var id = req.params.id.replace(/\D/g, "")
+ if (! id) {
+ return res.sendStatus(404)
+ }
+ db.getFileById(id).then(function(file){
+ console.log(file)
+ if (file) {
+ res.file = file
+ next()
+ }
+ else {
+ res.sendStatus(404)
+ }
+ })
+ },
createOptionalFiles: function(req, res, next){
if (! req.files || ! req.files.length) {
return next()
@@ -418,6 +434,11 @@ var bucky = module.exports = {
console.log(err)
})
},
+ destroyFile: function(req,res,next){
+ var filePromises = db.destroyFiles([res.file])
+ Promise.all(filePromises).then( () => next() )
+ .catch(err => { console.error(err); next() })
+ },
/* PROFILE / USER */
@@ -499,6 +520,13 @@ var bucky = module.exports = {
}
next()
},
+ checkFilePrivacy: function(req, res, next) {
+ console.log(res.file)
+ if (req.user.get('ulevel') !== 3 && req.user.get('username') !== res.file.get('username')) {
+ return res.sendStatus(500)
+ }
+ next()
+ },
checkMessagePrivacy: function(req, res, next) {
var username = req.user.get('username')
if (username !== res.message.get('sender') && username !== res.message.get('recipient')) {