From bb0f7465980e0245eefa663636354922c8c1c868 Mon Sep 17 00:00:00 2001 From: Pitu Date: Thu, 19 Jan 2017 17:14:28 -0300 Subject: [PATCH] Album delete WIP --- controllers/albumsController.js | 15 ++++++++++++++- controllers/uploadController.js | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/controllers/albumsController.js b/controllers/albumsController.js index 55885f5..47ab1d5 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -48,7 +48,7 @@ albumsController.create = function(req, res, next){ if(name === undefined || name === '') return res.json({ success: false, description: 'No album name specified' }) - db.table('albums').where('name', name).then((album) => { + db.table('albums').where('name', name).where('enabled', 1).then((album) => { if(album.length !== 0) return res.json({ success: false, description: 'There\'s already an album with that name' }) db.table('albums').insert({ @@ -61,5 +61,18 @@ albumsController.create = function(req, res, next){ }) } +albumsController.delete = function(req, res, next){ + if(req.headers.auth !== config.adminToken) + return res.status(401).json({ success: false, description: 'not-authorized'}) + + let id = req.body.id + if(id === undefined || id === '') + return res.json({ success: false, description: 'No album specified' }) + + db.table('albums').where('id', id).update({ enabled: 0 }).then(() => { + return res.json({ success: true }) + }) +} + module.exports = albumsController \ No newline at end of file diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 10ee4c7..87b3ab6 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -123,7 +123,6 @@ uploadsController.list = function(req, res){ for(let file of files){ file.file = 'http://' + basedomain + '/' + file.name - //file.file = config.basedomain + config.uploads.prefix + file.name file.date = new Date(file.timestamp * 1000) file.date = file.date.getFullYear() + '-' + (file.date.getMonth() + 1) + '-' + file.date.getDate() + ' ' + (file.date.getHours() < 10 ? '0' : '') + file.date.getHours() + ':' + (file.date.getMinutes() < 10 ? '0' : '') + file.date.getMinutes() + ':' + (file.date.getSeconds() < 10 ? '0' : '') + file.date.getSeconds()