SEMICOLONS, ermahgerd (#93)

This commit is contained in:
Bobby Wibowo 2018-04-26 13:50:35 +07:00 committed by Crawl
parent 5a4bec6b00
commit 19e965a77a
7 changed files with 80 additions and 80 deletions

View File

@ -23,8 +23,8 @@ albumsController.list = async (req, res, next) => {
let ids = []; let ids = [];
for (let album of albums) { for (let album of albums) {
album.date = new Date(album.timestamp * 1000) album.date = new Date(album.timestamp * 1000);
album.date = utils.getPrettyDate(album.date) album.date = utils.getPrettyDate(album.date);
album.identifier = `${config.domain}/a/${album.identifier}`; album.identifier = `${config.domain}/a/${album.identifier}`;
ids.push(album.id); ids.push(album.id);
@ -55,7 +55,7 @@ albumsController.create = async (req, res, next) => {
}).first(); }).first();
if (album) { 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({ 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(); const album = await db.table('albums').where({ name: name, userid: user.id }).first();
if (album) { 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 }); return res.json({ success: true });
}; };

View File

@ -42,10 +42,10 @@ authController.register = async (req, res, next) => {
if (password === undefined) return res.json({ success: false, description: 'No password provided' }); if (password === undefined) return res.json({ success: false, description: 'No password provided' });
if (username.length < 4 || username.length > 32) { 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) { 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(); const user = await db.table('users').where('username', username).first();
@ -63,7 +63,7 @@ authController.register = async (req, res, next) => {
token: token, token: token,
enabled: 1 enabled: 1
}); });
return res.json({ success: true, token: token }) return res.json({ success: true, token: token });
}); });
}; };

View File

@ -19,7 +19,7 @@ utilsController.getPrettyDate = function(date) {
+ date.getMinutes() + ':' + date.getMinutes() + ':'
+ (date.getSeconds() < 10 ? '0' : '') + (date.getSeconds() < 10 ? '0' : '')
+ date.getSeconds(); + date.getSeconds();
} };
utilsController.authorize = async (req, res) => { utilsController.authorize = async (req, res) => {
const token = req.headers.token; const token = req.headers.token;

View File

@ -2,52 +2,52 @@ let init = function(db){
// Create the tables we need to store galleries and files // Create the tables we need to store galleries and files
db.schema.createTableIfNotExists('albums', function (table) { db.schema.createTableIfNotExists('albums', function (table) {
table.increments() table.increments();
table.integer('userid') table.integer('userid');
table.string('name') table.string('name');
table.string('identifier') table.string('identifier');
table.integer('enabled') table.integer('enabled');
table.integer('timestamp') table.integer('timestamp');
table.integer('editedAt'); table.integer('editedAt');
table.integer('zipGeneratedAt'); table.integer('zipGeneratedAt');
}).then(() => {}) }).then(() => {});
db.schema.createTableIfNotExists('files', function (table) { db.schema.createTableIfNotExists('files', function (table) {
table.increments() table.increments();
table.integer('userid') table.integer('userid');
table.string('name') table.string('name');
table.string('original') table.string('original');
table.string('type') table.string('type');
table.string('size') table.string('size');
table.string('hash') table.string('hash');
table.string('ip') table.string('ip');
table.integer('albumid') table.integer('albumid');
table.integer('timestamp') table.integer('timestamp');
}).then(() => {}) }).then(() => {});
db.schema.createTableIfNotExists('users', function (table) { db.schema.createTableIfNotExists('users', function (table) {
table.increments() table.increments();
table.string('username') table.string('username');
table.string('password') table.string('password');
table.string('token') table.string('token');
table.integer('enabled') table.integer('enabled');
table.integer('timestamp') table.integer('timestamp');
}).then(() => { }).then(() => {
db.table('users').where({username: 'root'}).then((user) => { 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) { 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({ db.table('users').insert({
username: 'root', username: 'root',
password: hash, password: hash,
token: require('randomstring').generate(64), token: require('randomstring').generate(64),
timestamp: Math.floor(Date.now() / 1000) timestamp: Math.floor(Date.now() / 1000)
}).then(() => {}) }).then(() => {});
}) });
}) });
}) });
} };
module.exports = init module.exports = init;

View File

@ -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'); return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error); console.log(error);
}); });
} };
page.verify = function(){ page.verify = function(){
page.token = localStorage.token; page.token = localStorage.token;
@ -49,8 +49,8 @@ page.verify = function(){
console.log(error); console.log(error);
}); });
} };
window.onload = function () { window.onload = function () {
page.verify(); page.verify();
} };

View File

@ -1,4 +1,4 @@
let panel = {} let panel = {};
panel.page; panel.page;
panel.username; panel.username;
@ -8,7 +8,7 @@ panel.filesView = localStorage.filesView;
panel.preparePage = function(){ panel.preparePage = function(){
if(!panel.token) return window.location = '/auth'; if(!panel.token) return window.location = '/auth';
panel.verifyToken(panel.token, true); panel.verifyToken(panel.token, true);
} };
panel.verifyToken = function(token, reloadOnError){ panel.verifyToken = function(token, reloadOnError){
if(reloadOnError === undefined) if(reloadOnError === undefined)
@ -29,7 +29,7 @@ panel.verifyToken = function(token, reloadOnError){
localStorage.removeItem("token"); localStorage.removeItem("token");
location.location = '/auth'; location.location = '/auth';
} }
}) });
return; return;
} }
@ -45,7 +45,7 @@ panel.verifyToken = function(token, reloadOnError){
console.log(error); console.log(error);
}); });
} };
panel.prepareDashboard = function(){ panel.prepareDashboard = function(){
panel.page = document.getElementById('page'); panel.page = document.getElementById('page');
@ -71,20 +71,20 @@ panel.prepareDashboard = function(){
document.getElementById('itemLogout').innerHTML = `Logout ( ${panel.username} )`; document.getElementById('itemLogout').innerHTML = `Logout ( ${panel.username} )`;
panel.getAlbumsSidebar(); panel.getAlbumsSidebar();
} };
panel.logout = function(){ panel.logout = function(){
localStorage.removeItem("token"); localStorage.removeItem("token");
location.reload('/'); location.reload('/');
} };
panel.getUploads = function(album = undefined, page = undefined){ panel.getUploads = function(album = undefined, page = undefined){
if(page === undefined) page = 0; if(page === undefined) page = 0;
let url = '/api/uploads/' + page let url = '/api/uploads/' + page;
if(album !== undefined) if(album !== undefined)
url = '/api/album/' + album + '/' + page url = '/api/album/' + album + '/' + page;
axios.get(url).then(function (response) { axios.get(url).then(function (response) {
if(response.data.success === false){ if(response.data.success === false){
@ -120,7 +120,7 @@ panel.getUploads = function(album = undefined, page = undefined){
</span> </span>
</a> </a>
</div> </div>
</div>` </div>`;
if(panel.filesView === 'thumbs'){ if(panel.filesView === 'thumbs'){
@ -213,13 +213,13 @@ panel.getUploads = function(album = undefined, page = undefined){
console.log(error); console.log(error);
}); });
} };
panel.setFilesView = function(view, album, page){ panel.setFilesView = function(view, album, page){
localStorage.filesView = view; localStorage.filesView = view;
panel.filesView = view; panel.filesView = view;
panel.getUploads(album, page); panel.getUploads(album, page);
} };
panel.deleteFile = function(id){ panel.deleteFile = function(id){
swal({ swal({
@ -254,7 +254,7 @@ panel.deleteFile = function(id){
} }
); );
} };
panel.getAlbums = function(){ panel.getAlbums = function(){
@ -331,7 +331,7 @@ panel.getAlbums = function(){
console.log(error); console.log(error);
}); });
} };
panel.renameAlbum = function(id){ panel.renameAlbum = function(id){
@ -347,7 +347,7 @@ panel.renameAlbum = function(id){
if (inputValue === false) return false; if (inputValue === false) return false;
if (inputValue === "") { if (inputValue === "") {
swal.showInputError("You need to write something!"); swal.showInputError("You need to write something!");
return false return false;
} }
axios.post('/api/albums/rename', { axios.post('/api/albums/rename', {
@ -375,7 +375,7 @@ panel.renameAlbum = function(id){
}); });
} };
panel.deleteAlbum = function(id){ panel.deleteAlbum = function(id){
swal({ swal({
@ -412,7 +412,7 @@ panel.deleteAlbum = function(id){
} }
); );
} };
panel.submitAlbum = function(){ panel.submitAlbum = function(){
@ -436,7 +436,7 @@ panel.submitAlbum = function(){
console.log(error); console.log(error);
}); });
} };
panel.getAlbumsSidebar = function(){ panel.getAlbumsSidebar = function(){
@ -474,12 +474,12 @@ panel.getAlbumsSidebar = function(){
console.log(error); console.log(error);
}); });
} };
panel.getAlbum = function(item){ panel.getAlbum = function(item){
panel.setActiveMenu(item); panel.setActiveMenu(item);
panel.getUploads(item.id); panel.getUploads(item.id);
} };
panel.changeToken = function(){ panel.changeToken = function(){
@ -515,7 +515,7 @@ panel.changeToken = function(){
console.log(error); console.log(error);
}); });
} };
panel.getNewToken = function(){ panel.getNewToken = function(){
@ -534,7 +534,7 @@ panel.getNewToken = function(){
}, function(){ }, function(){
localStorage.token = response.data.token; localStorage.token = response.data.token;
location.reload(); location.reload();
}) });
}) })
.catch(function (error) { .catch(function (error) {
@ -542,7 +542,7 @@ panel.getNewToken = function(){
console.log(error); console.log(error);
}); });
} };
panel.changePassword = function(){ panel.changePassword = function(){
@ -578,7 +578,7 @@ panel.changePassword = function(){
}); });
} }
}); });
} };
panel.sendNewPassword = function(pass){ panel.sendNewPassword = function(pass){
@ -596,7 +596,7 @@ panel.sendNewPassword = function(pass){
type: "success" type: "success"
}, function(){ }, function(){
location.reload(); location.reload();
}) });
}) })
.catch(function (error) { .catch(function (error) {
@ -604,7 +604,7 @@ panel.sendNewPassword = function(pass){
console.log(error); console.log(error);
}); });
} };
panel.setActiveMenu = function(item){ panel.setActiveMenu = function(item){
var menu = document.getElementById('menu'); var menu = document.getElementById('menu');
@ -613,8 +613,8 @@ panel.setActiveMenu = function(item){
items[i].className = ""; items[i].className = "";
item.className = 'is-active'; item.className = 'is-active';
} };
window.onload = function () { window.onload = function () {
panel.preparePage(); panel.preparePage();
} };

View File

@ -24,7 +24,7 @@ upload.preparePage = function(){
if(!upload.isPrivate) return upload.prepareUpload(); if(!upload.isPrivate) return upload.prepareUpload();
if(!upload.token) return document.getElementById('loginToUpload').style.display = 'inline-flex'; if(!upload.token) return document.getElementById('loginToUpload').style.display = 'inline-flex';
upload.verifyToken(upload.token, true); upload.verifyToken(upload.token, true);
} };
upload.verifyToken = function(token, reloadOnError){ upload.verifyToken = function(token, reloadOnError){
if(reloadOnError === undefined) if(reloadOnError === undefined)
@ -45,7 +45,7 @@ upload.verifyToken = function(token, reloadOnError){
localStorage.removeItem("token"); localStorage.removeItem("token");
location.reload(); location.reload();
} }
}) });
return; return;
} }
@ -59,7 +59,7 @@ upload.verifyToken = function(token, reloadOnError){
return console.log(error); return console.log(error);
}); });
} };
upload.prepareUpload = function(){ upload.prepareUpload = function(){
// I think this fits best here because we need to check for a valid token before we can get the albums // 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) { .catch(function(e) {
swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
return console.log(e); return console.log(e);
}) });
} }
div = document.createElement('div'); div = document.createElement('div');
@ -109,7 +109,7 @@ upload.prepareUpload = function(){
upload.prepareDropzone(); upload.prepareDropzone();
} };
upload.prepareDropzone = function(){ upload.prepareDropzone = function(){
var previewNode = document.querySelector('#template'); var previewNode = document.querySelector('#template');
@ -139,7 +139,7 @@ upload.prepareDropzone = function(){
// add the selected albumid, if an album is selected, as a header // add the selected albumid, if an album is selected, as a header
this.on('sending', function(file, xhr) { this.on('sending', function(file, xhr) {
if (upload.album) { if (upload.album) {
xhr.setRequestHeader('albumid', upload.album) xhr.setRequestHeader('albumid', upload.album);
} }
}); });
} }
@ -173,7 +173,7 @@ upload.prepareDropzone = function(){
}); });
upload.prepareShareX(); upload.prepareShareX();
} };
upload.prepareShareX = function(){ upload.prepareShareX = function(){
if (upload.token) { if (upload.token) {
@ -192,10 +192,10 @@ upload.prepareShareX = function(){
\"ThumbnailURL\": \"$json:files[0].url$\"\r\n\ \"ThumbnailURL\": \"$json:files[0].url$\"\r\n\
}"; }";
var sharex_blob = new Blob([sharex_file], {type: "application/octet-binary"}); 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"); sharex_element.setAttribute("download", location.hostname + ".sxcu");
} }
} };
//Handle image paste event //Handle image paste event
window.addEventListener('paste', function(event) { window.addEventListener('paste', function(event) {