diff --git a/controllers/albumsController.js b/controllers/albumsController.js index ed57cac..a395f9b 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -23,8 +23,8 @@ albumsController.list = async (req, res, next) => { let ids = []; for (let album of albums) { - album.date = new Date(album.timestamp * 1000) - album.date = utils.getPrettyDate(album.date) + album.date = new Date(album.timestamp * 1000); + album.date = utils.getPrettyDate(album.date); album.identifier = `${config.domain}/a/${album.identifier}`; ids.push(album.id); @@ -55,7 +55,7 @@ albumsController.create = async (req, res, next) => { }).first(); if (album) { - return res.json({ success: false, description: 'There\'s already an album with that name' }) + return res.json({ success: false, description: 'There\'s already an album with that name' }); } await db.table('albums').insert({ @@ -96,10 +96,10 @@ albumsController.rename = async (req, res, next) => { const album = await db.table('albums').where({ name: name, userid: user.id }).first(); if (album) { - return res.json({ success: false, description: 'Name already in use' }) + return res.json({ success: false, description: 'Name already in use' }); } - await db.table('albums').where({ id: id, userid: user.id }).update({ name: name }) + await db.table('albums').where({ id: id, userid: user.id }).update({ name: name }); return res.json({ success: true }); }; diff --git a/controllers/authController.js b/controllers/authController.js index ea32275..eb7df09 100644 --- a/controllers/authController.js +++ b/controllers/authController.js @@ -42,10 +42,10 @@ authController.register = async (req, res, next) => { if (password === undefined) return res.json({ success: false, description: 'No password provided' }); if (username.length < 4 || username.length > 32) { - return res.json({ success: false, description: 'Username must have 4-32 characters' }) + return res.json({ success: false, description: 'Username must have 4-32 characters' }); } if (password.length < 6 || password.length > 64) { - return res.json({ success: false, description: 'Password must have 6-64 characters' }) + return res.json({ success: false, description: 'Password must have 6-64 characters' }); } const user = await db.table('users').where('username', username).first(); @@ -63,7 +63,7 @@ authController.register = async (req, res, next) => { token: token, enabled: 1 }); - return res.json({ success: true, token: token }) + return res.json({ success: true, token: token }); }); }; diff --git a/controllers/utilsController.js b/controllers/utilsController.js index ebfb36d..bc182b7 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -19,7 +19,7 @@ utilsController.getPrettyDate = function(date) { + date.getMinutes() + ':' + (date.getSeconds() < 10 ? '0' : '') + date.getSeconds(); -} +}; utilsController.authorize = async (req, res) => { const token = req.headers.token; diff --git a/database/db.js b/database/db.js index 40c6e13..8655f76 100644 --- a/database/db.js +++ b/database/db.js @@ -2,52 +2,52 @@ let init = function(db){ // Create the tables we need to store galleries and files db.schema.createTableIfNotExists('albums', function (table) { - table.increments() - table.integer('userid') - table.string('name') - table.string('identifier') - table.integer('enabled') - table.integer('timestamp') + table.increments(); + table.integer('userid'); + table.string('name'); + table.string('identifier'); + table.integer('enabled'); + table.integer('timestamp'); table.integer('editedAt'); table.integer('zipGeneratedAt'); - }).then(() => {}) + }).then(() => {}); db.schema.createTableIfNotExists('files', function (table) { - table.increments() - table.integer('userid') - table.string('name') - table.string('original') - table.string('type') - table.string('size') - table.string('hash') - table.string('ip') - table.integer('albumid') - table.integer('timestamp') - }).then(() => {}) + table.increments(); + table.integer('userid'); + table.string('name'); + table.string('original'); + table.string('type'); + table.string('size'); + table.string('hash'); + table.string('ip'); + table.integer('albumid'); + table.integer('timestamp'); + }).then(() => {}); db.schema.createTableIfNotExists('users', function (table) { - table.increments() - table.string('username') - table.string('password') - table.string('token') - table.integer('enabled') - table.integer('timestamp') + table.increments(); + table.string('username'); + table.string('password'); + table.string('token'); + table.integer('enabled'); + table.integer('timestamp'); }).then(() => { db.table('users').where({username: 'root'}).then((user) => { - if(user.length > 0) return + if(user.length > 0) return; require('bcrypt').hash('root', 10, function(err, hash) { - if(err) console.error('Error generating password hash for root') + if(err) console.error('Error generating password hash for root'); db.table('users').insert({ username: 'root', password: hash, token: require('randomstring').generate(64), timestamp: Math.floor(Date.now() / 1000) - }).then(() => {}) - }) - }) - }) -} + }).then(() => {}); + }); + }); + }); +}; -module.exports = init +module.exports = init; diff --git a/public/js/auth.js b/public/js/auth.js index ecc7c7c..1ae9e4d 100644 --- a/public/js/auth.js +++ b/public/js/auth.js @@ -27,7 +27,7 @@ page.do = function(dest){ return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error'); console.log(error); }); -} +}; page.verify = function(){ page.token = localStorage.token; @@ -49,8 +49,8 @@ page.verify = function(){ console.log(error); }); -} +}; window.onload = function () { page.verify(); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/public/js/dashboard.js b/public/js/dashboard.js index 9b1d8ca..a4de774 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -1,4 +1,4 @@ -let panel = {} +let panel = {}; panel.page; panel.username; @@ -8,7 +8,7 @@ panel.filesView = localStorage.filesView; panel.preparePage = function(){ if(!panel.token) return window.location = '/auth'; panel.verifyToken(panel.token, true); -} +}; panel.verifyToken = function(token, reloadOnError){ if(reloadOnError === undefined) @@ -29,7 +29,7 @@ panel.verifyToken = function(token, reloadOnError){ localStorage.removeItem("token"); location.location = '/auth'; } - }) + }); return; } @@ -45,7 +45,7 @@ panel.verifyToken = function(token, reloadOnError){ console.log(error); }); -} +}; panel.prepareDashboard = function(){ panel.page = document.getElementById('page'); @@ -71,20 +71,20 @@ panel.prepareDashboard = function(){ document.getElementById('itemLogout').innerHTML = `Logout ( ${panel.username} )`; panel.getAlbumsSidebar(); -} +}; panel.logout = function(){ localStorage.removeItem("token"); location.reload('/'); -} +}; panel.getUploads = function(album = undefined, page = undefined){ if(page === undefined) page = 0; - let url = '/api/uploads/' + page + let url = '/api/uploads/' + page; if(album !== undefined) - url = '/api/album/' + album + '/' + page + url = '/api/album/' + album + '/' + page; axios.get(url).then(function (response) { if(response.data.success === false){ @@ -120,7 +120,7 @@ panel.getUploads = function(album = undefined, page = undefined){ - ` + `; if(panel.filesView === 'thumbs'){ @@ -213,13 +213,13 @@ panel.getUploads = function(album = undefined, page = undefined){ console.log(error); }); -} +}; panel.setFilesView = function(view, album, page){ localStorage.filesView = view; panel.filesView = view; panel.getUploads(album, page); -} +}; panel.deleteFile = function(id){ swal({ @@ -254,7 +254,7 @@ panel.deleteFile = function(id){ } ); -} +}; panel.getAlbums = function(){ @@ -331,7 +331,7 @@ panel.getAlbums = function(){ console.log(error); }); -} +}; panel.renameAlbum = function(id){ @@ -347,7 +347,7 @@ panel.renameAlbum = function(id){ if (inputValue === false) return false; if (inputValue === "") { swal.showInputError("You need to write something!"); - return false + return false; } axios.post('/api/albums/rename', { @@ -375,7 +375,7 @@ panel.renameAlbum = function(id){ }); -} +}; panel.deleteAlbum = function(id){ swal({ @@ -412,7 +412,7 @@ panel.deleteAlbum = function(id){ } ); -} +}; panel.submitAlbum = function(){ @@ -436,7 +436,7 @@ panel.submitAlbum = function(){ console.log(error); }); -} +}; panel.getAlbumsSidebar = function(){ @@ -474,12 +474,12 @@ panel.getAlbumsSidebar = function(){ console.log(error); }); -} +}; panel.getAlbum = function(item){ panel.setActiveMenu(item); panel.getUploads(item.id); -} +}; panel.changeToken = function(){ @@ -515,7 +515,7 @@ panel.changeToken = function(){ console.log(error); }); -} +}; panel.getNewToken = function(){ @@ -534,7 +534,7 @@ panel.getNewToken = function(){ }, function(){ localStorage.token = response.data.token; location.reload(); - }) + }); }) .catch(function (error) { @@ -542,7 +542,7 @@ panel.getNewToken = function(){ console.log(error); }); -} +}; panel.changePassword = function(){ @@ -578,7 +578,7 @@ panel.changePassword = function(){ }); } }); -} +}; panel.sendNewPassword = function(pass){ @@ -596,7 +596,7 @@ panel.sendNewPassword = function(pass){ type: "success" }, function(){ location.reload(); - }) + }); }) .catch(function (error) { @@ -604,7 +604,7 @@ panel.sendNewPassword = function(pass){ console.log(error); }); -} +}; panel.setActiveMenu = function(item){ var menu = document.getElementById('menu'); @@ -613,8 +613,8 @@ panel.setActiveMenu = function(item){ items[i].className = ""; item.className = 'is-active'; -} +}; window.onload = function () { panel.preparePage(); -} +}; diff --git a/public/js/home.js b/public/js/home.js index 35c65a4..383e245 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -24,7 +24,7 @@ upload.preparePage = function(){ if(!upload.isPrivate) return upload.prepareUpload(); if(!upload.token) return document.getElementById('loginToUpload').style.display = 'inline-flex'; upload.verifyToken(upload.token, true); -} +}; upload.verifyToken = function(token, reloadOnError){ if(reloadOnError === undefined) @@ -45,7 +45,7 @@ upload.verifyToken = function(token, reloadOnError){ localStorage.removeItem("token"); location.reload(); } - }) + }); return; } @@ -59,7 +59,7 @@ upload.verifyToken = function(token, reloadOnError){ return console.log(error); }); -} +}; upload.prepareUpload = function(){ // I think this fits best here because we need to check for a valid token before we can get the albums @@ -91,7 +91,7 @@ upload.prepareUpload = function(){ .catch(function(e) { swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); return console.log(e); - }) + }); } div = document.createElement('div'); @@ -109,7 +109,7 @@ upload.prepareUpload = function(){ upload.prepareDropzone(); -} +}; upload.prepareDropzone = function(){ var previewNode = document.querySelector('#template'); @@ -139,7 +139,7 @@ upload.prepareDropzone = function(){ // add the selected albumid, if an album is selected, as a header this.on('sending', function(file, xhr) { if (upload.album) { - xhr.setRequestHeader('albumid', upload.album) + xhr.setRequestHeader('albumid', upload.album); } }); } @@ -173,7 +173,7 @@ upload.prepareDropzone = function(){ }); upload.prepareShareX(); -} +}; upload.prepareShareX = function(){ if (upload.token) { @@ -192,10 +192,10 @@ upload.prepareShareX = function(){ \"ThumbnailURL\": \"$json:files[0].url$\"\r\n\ }"; var sharex_blob = new Blob([sharex_file], {type: "application/octet-binary"}); - sharex_element.setAttribute("href", URL.createObjectURL(sharex_blob)) + sharex_element.setAttribute("href", URL.createObjectURL(sharex_blob)); sharex_element.setAttribute("download", location.hostname + ".sxcu"); } -} +}; //Handle image paste event window.addEventListener('paste', function(event) {