Fixed last night's fuckup

This commit is contained in:
Pitu 2017-08-30 19:35:40 -03:00
parent 80117235f9
commit ad4eeb5eaa

View File

@ -62,6 +62,12 @@ uploadsController.upload = function(req, res, next) {
album = req.params.albumid album = req.params.albumid
} }
/*
A rewrite is due so might as well do awful things here and fix them later :bloblul:
*/
if (album !== undefined && userid !== undefined) {
// If both values are present, check if the album owner is the user uploading
db.table('albums').where({ id: album, userid: userid }).then((albums) => { db.table('albums').where({ id: album, userid: userid }).then((albums) => {
if (albums.length === 0) { if (albums.length === 0) {
return res.json({ return res.json({
@ -69,7 +75,15 @@ uploadsController.upload = function(req, res, next) {
description: 'Album doesn\'t exist or it doesn\'t belong to the user' description: 'Album doesn\'t exist or it doesn\'t belong to the user'
}) })
} }
uploadsController.actuallyUpload(req, res, userid, album);
})
} else {
uploadsController.actuallyUpload(req, res, userid, album);
}
}).catch(function(error) { console.log(error); res.json({ success: false, description: 'error' }) })
}
uploadsController.actuallyUpload = function(req, res, userid, album) {
upload(req, res, function (err) { upload(req, res, function (err) {
if (err) { if (err) {
console.error(err) console.error(err)
@ -134,10 +148,7 @@ uploadsController.upload = function(req, res, next) {
}) })
}) })
}) })
})
}).catch(function(error) { console.log(error); res.json({ success: false, description: 'error' }) })
} }
uploadsController.processFilesForDisplay = function(req, res, files, existingFiles) { uploadsController.processFilesForDisplay = function(req, res, files, existingFiles) {
let basedomain = req.get('host') let basedomain = req.get('host')