More breaking changes

* Added Editor Config file.

* Added ".vscode/" to .gitignore.

* Added final newline to some files.

* Added KDE Breeze Dark colors.

 * Applied various ESLint autofixes. There were still plenty of non-auto-fixable issues though. I'm not sure why this project had ESLint dev dependency but still ended up with countless issues.

* ... and maybe some others.
This commit is contained in:
Bobby Wibowo 2018-01-24 01:00:55 +07:00
parent 883a601358
commit 47f2f30682
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
12 changed files with 545 additions and 509 deletions

10
.editorconfig Normal file
View File

@ -0,0 +1,10 @@
[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@ -81,4 +81,4 @@ module.exports = {
connection: { filename: './database/db' },
useNullAsDefault: true
}
}
};

View File

@ -13,10 +13,10 @@ const safe = express();
require('./database/db.js')(db);
fs.existsSync('./pages/custom') || fs.mkdirSync('./pages/custom');
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder);
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder);
fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs');
fs.existsSync('./' + config.uploads.folder + '/zips') || fs.mkdirSync('./' + config.uploads.folder + '/zips')
fs.existsSync(`./${config.logsFolder}`) || fs.mkdirSync(`./${ config.logsFolder}`);
fs.existsSync(`./${config.uploads.folder}`) || fs.mkdirSync(`./${config.uploads.folder}`);
fs.existsSync(`./${config.uploads.folder}/thumbs`) || fs.mkdirSync(`./${config.uploads.folder }/thumbs`);
fs.existsSync(`./${config.uploads.folder }/zips`) || fs.mkdirSync(`./${config.uploads.folder}/zips`);
safe.use(helmet());
safe.set('trust proxy', 1);

View File

@ -39,14 +39,15 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.15.3/axios.min.js"></script>
<script type="text/javascript" src="https://use.fontawesome.com/cd26baa9bd.js"></script>
<script type="text/javascript" src="/js/auth.js"></script>
</head>
<body>
<style type="text/css">
/** Based on KDE Breeze Dark **/
section#login {
background-color: #f5f6f8;
background-color: #232629;
}
</style>
</head>
<body>
<section id='login' class="hero is-fullheight">
<div class="hero-body">

View File

@ -39,6 +39,89 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.15.3/axios.min.js"></script>
<script type="text/javascript" src="https://use.fontawesome.com/cd26baa9bd.js"></script>
<script type="text/javascript" src="/js/dashboard.js"></script>
<style type="text/css">
/** Based on KDE Breeze Dark **/
html {
background-color: #232629;
}
.section {
background: none;
}
.menu-list a {
color: #2980b9;
}
.menu-list a:hover {
color: #3daee9;
background-color: #4d4d4d;
}
.menu-list a.is-active {
color: #eff0f1;
background-color: #2980b9;
}
.button.is-primary {
background-color: #2980b9;
}
.button.is-primary.is-hovered, .button.is-primary:hover {
background-color: #2980b9;
}
.pagination a {
color: #eff0f1;
border-color: #4d4d4d;
background-color: #31363b;
}
.pagination-link:hover, .pagination-next:hover, .pagination-previous:hover {
color: #eff0f1;
border-color: #3daee9;
background-color: #31363b;
}
.label {
color: #bdc3c7;
}
.table {
color: #bdc3c7;
background-color: #31363b;
}
.table tr:hover, .table.is-striped tbody tr:nth-child(2n) {
background: none;
}
.table.is-striped tbody tr:hover, .table.is-striped tbody tr:nth-child(2n):hover, .tag {
background-color: #4d4d4d;
}
.table thead td, .table thead th {
color: #eff0f1;
background-color: #ff3860;
}
.table th {
color: #eff0f1;
}
.table td, .table th {
border: 0;
}
section#dashboard div#table div.column {
background-color: #31363b;
}
.menu-list li ul {
border-left-color: #31363b;
}
</style>
</head>
<body>

View File

@ -110,3 +110,40 @@ section#dashboard div#table div.column a img { width:200px; }
text-align: center;
margin-bottom: 10px;
}
/** Based on KDE Breeze Dark **/
.hero {
background-color: #232629;
color: #eff0f1;
}
.title {
color: #eff0f1;
}
.subtitle {
color: #bdc3c7;
}
.subtitle strong {
color: #bdc3c7;
}
a {
color: #2980b9;
}
a:hover {
color: #3daee9;
}
section#home h3#links span {
color: #4d4d4d;
}
section#home #b {
width: 200px;
height: 200px;
border-radius: 100%;
}

View File

@ -1,56 +1,44 @@
var page = {};
page.do = function(dest) {
var user = document.getElementById('user').value;
var pass = document.getElementById('pass').value;
if(user === undefined || user === null || user === '')
return swal('Error', 'You need to specify a username', 'error');
if(pass === undefined || pass === null || pass === '')
return swal('Error', 'You need to specify a username', 'error');
if (user === undefined || user === null || user === '') { return swal('Error', 'You need to specify a username', 'error'); }
if (pass === undefined || pass === null || pass === '') { return swal('Error', 'You need to specify a username', 'error'); }
axios.post('/api/' + dest, {
axios.post(`/api/${dest}`, {
username: user,
password: pass
})
.then(function (response) {
if(response.data.success === false)
return swal('Error', response.data.description, 'error');
.then(response => {
if (response.data.success === false) { return swal('Error', response.data.description, 'error'); }
localStorage.token = response.data.token;
window.location = '/dashboard';
})
.catch(function (error) {
.catch(error => {
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;
if (page.token === undefined) return;
axios.post('/api/tokens/verify', {
token: page.token
})
.then(function (response) {
if(response.data.success === false)
return swal('Error', response.data.description, 'error');
axios.post('/api/tokens/verify', { token: page.token })
.then(response => {
if (response.data.success === false) { return swal('Error', response.data.description, 'error'); }
window.location = '/dashboard';
})
.catch(function (error) {
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
window.onload = function() {
page.verify();
}
};

View File

@ -1,4 +1,4 @@
let panel = {}
let panel = {};
panel.page;
panel.username;
@ -8,44 +8,38 @@ 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)
reloadOnError = false;
axios.post('/api/tokens/verify', {
token: token
})
.then(function (response) {
if (reloadOnError === undefined) { reloadOnError = false; }
axios.post('/api/tokens/verify', { token: token })
.then(response => {
if (response.data.success === false) {
swal({
title: "An error ocurred",
title: 'An error ocurred',
text: response.data.description,
type: "error"
}, function(){
type: 'error'
}, () => {
if (reloadOnError) {
localStorage.removeItem("token");
localStorage.removeItem('token');
location.location = '/auth';
}
})
});
return;
}
axios.defaults.headers.common['token'] = token;
axios.defaults.headers.common.token = token;
localStorage.token = token;
panel.token = token;
panel.username = response.data.username;
return panel.prepareDashboard();
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.prepareDashboard = function() {
panel.page = document.getElementById('page');
@ -71,32 +65,29 @@ panel.prepareDashboard = function(){
document.getElementById('itemLogout').innerHTML = `Logout ( ${panel.username} )`;
panel.getAlbumsSidebar();
}
};
panel.logout = function() {
localStorage.removeItem("token");
localStorage.removeItem('token');
location.reload('/');
}
};
panel.getUploads = function(album = undefined, page = undefined) {
if (page === undefined) page = 0;
let url = '/api/uploads/' + page
if(album !== undefined)
url = '/api/album/' + album + '/' + page
let url = `/api/uploads/${page}`;
if (album !== undefined) { url = `/api/album/${album}/${page}`; }
axios.get(url).then(function (response) {
axios.get(url).then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
var prevPage = 0;
var nextPage = page + 1;
if(response.data.files.length < 25)
nextPage = page;
if (response.data.files.length < 25) { nextPage = page; }
if (page > 0) prevPage = page - 1;
@ -120,10 +111,9 @@ panel.getUploads = function(album = undefined, page = undefined){
</span>
</a>
</div>
</div>`
</div>`;
if (panel.filesView === 'thumbs') {
container.innerHTML = `
${pagination}
<hr>
@ -138,22 +128,14 @@ panel.getUploads = function(album = undefined, page = undefined){
var table = document.getElementById('table');
for (var item of response.data.files) {
var div = document.createElement('div');
div.className = "column is-2";
if(item.thumb !== undefined)
div.innerHTML = `<a href="${item.file}" target="_blank"><img src="${item.thumb}"/></a>`;
else
div.innerHTML = `<a href="${item.file}" target="_blank"><h1 class="title">.${item.file.split('.').pop()}</h1></a>`;
div.className = 'column is-2';
if (item.thumb !== undefined) { div.innerHTML = `<a href="${item.file}" target="_blank"><img src="${item.thumb}"/></a>`; } else { div.innerHTML = `<a href="${item.file}" target="_blank"><h1 class="title">.${item.file.split('.').pop()}</h1></a>`; }
table.appendChild(div);
}
} else {
var albumOrUser = 'Album';
if(panel.username === 'root')
albumOrUser = 'User';
if (panel.username === 'root') { albumOrUser = 'User'; }
container.innerHTML = `
${pagination}
@ -179,14 +161,12 @@ panel.getUploads = function(album = undefined, page = undefined){
var table = document.getElementById('table');
for (var item of response.data.files) {
var tr = document.createElement('tr');
var displayAlbumOrUser = item.album;
if (panel.username === 'root') {
displayAlbumOrUser = '';
if(item.username !== undefined)
displayAlbumOrUser = item.username;
if (item.username !== undefined) { displayAlbumOrUser = item.username; }
}
tr.innerHTML = `
@ -208,66 +188,57 @@ panel.getUploads = function(album = undefined, page = undefined){
}
}
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.setFilesView = function(view, album, page) {
localStorage.filesView = view;
panel.filesView = view;
panel.getUploads(album, page);
}
};
panel.deleteFile = function(id) {
swal({
title: "Are you sure?",
text: "You wont be able to recover the file!",
type: "warning",
title: 'Are you sure?',
text: 'You wont be able to recover the file!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: "#ff3860",
confirmButtonText: "Yes, delete it!",
confirmButtonColor: '#ff3860',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false
},
function(){
axios.post('/api/upload/delete', {
id: id
})
.then(function (response) {
() => {
axios.post('/api/upload/delete', { id: id })
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
swal("Deleted!", "The file has been deleted.", "success");
swal('Deleted!', 'The file has been deleted.', 'success');
panel.getUploads();
return;
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
);
}
};
panel.getAlbums = function() {
axios.get('/api/albums').then(function (response) {
axios.get('/api/albums').then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
panel.page.innerHTML = '';
var container = document.createElement('div');
container.className = "container";
container.className = 'container';
container.innerHTML = `
<h2 class="subtitle">Create new album</h2>
@ -296,7 +267,6 @@ panel.getAlbums = function(){
var table = document.getElementById('table');
for (var item of response.data.albums) {
var tr = document.createElement('tr');
tr.innerHTML = `
<tr>
@ -322,133 +292,109 @@ panel.getAlbums = function(){
table.appendChild(tr);
}
document.getElementById('submitAlbum').addEventListener('click', function(){
document.getElementById('submitAlbum').addEventListener('click', () => {
panel.submitAlbum();
});
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.renameAlbum = function(id) {
swal({
title: "Rename album",
text: "New name you want to give the album:",
type: "input",
title: 'Rename album',
text: 'New name you want to give the album:',
type: 'input',
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "My super album"
},function(inputValue){
animation: 'slide-from-top',
inputPlaceholder: 'My super album'
}, inputValue => {
if (inputValue === false) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
if (inputValue === '') {
swal.showInputError('You need to write something!');
return false;
}
axios.post('/api/albums/rename', {
id: id,
name: inputValue
})
.then(function (response) {
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else if(response.data.description === 'Name already in use') swal.showInputError("That name is already in use!");
else swal("An error ocurred", response.data.description, "error");
else if (response.data.description === 'Name already in use') swal.showInputError('That name is already in use!');
else swal('An error ocurred', response.data.description, 'error');
return;
}
swal("Success!", "Your album was renamed to: " + inputValue, "success");
swal('Success!', `Your album was renamed to: ${inputValue}`, 'success');
panel.getAlbumsSidebar();
panel.getAlbums();
return;
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
});
}
};
panel.deleteAlbum = function(id) {
swal({
title: "Are you sure?",
title: 'Are you sure?',
text: "This won't delete your files, only the album!",
type: "warning",
type: 'warning',
showCancelButton: true,
confirmButtonColor: "#ff3860",
confirmButtonText: "Yes, delete it!",
confirmButtonColor: '#ff3860',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false
},
function(){
axios.post('/api/albums/delete', {
id: id
})
.then(function (response) {
() => {
axios.post('/api/albums/delete', { id: id })
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
swal("Deleted!", "Your album has been deleted.", "success");
swal('Deleted!', 'Your album has been deleted.', 'success');
panel.getAlbumsSidebar();
panel.getAlbums();
return;
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
);
}
};
panel.submitAlbum = function() {
axios.post('/api/albums', {
name: document.getElementById('albumName').value
})
.then(function (response) {
axios.post('/api/albums', { name: document.getElementById('albumName').value })
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
swal("Woohoo!", "Album was added successfully", "success");
swal('Woohoo!', 'Album was added successfully', 'success');
panel.getAlbumsSidebar();
panel.getAlbums();
return;
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.getAlbumsSidebar = function() {
axios.get('/api/albums/sidebar')
.then(function (response) {
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
var albumsContainer = document.getElementById('albumsContainer');
@ -457,7 +403,6 @@ panel.getAlbumsSidebar = function(){
if (response.data.albums === undefined) return;
for (var album of response.data.albums) {
li = document.createElement('li');
a = document.createElement('a');
a.id = album.id;
@ -470,33 +415,29 @@ panel.getAlbumsSidebar = function(){
li.appendChild(a);
albumsContainer.appendChild(li);
}
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.getAlbum = function(item) {
panel.setActiveMenu(item);
panel.getUploads(item.id);
}
};
panel.changeToken = function() {
axios.get('/api/tokens')
.then(function (response) {
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
panel.page.innerHTML = '';
var container = document.createElement('div');
container.className = "container";
container.className = 'container';
container.innerHTML = `
<h2 class="subtitle">Manage your token</h2>
@ -509,50 +450,43 @@ panel.changeToken = function(){
panel.page.appendChild(container);
document.getElementById('getNewToken').addEventListener('click', function(){
document.getElementById('getNewToken').addEventListener('click', () => {
panel.getNewToken();
});
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.getNewToken = function() {
axios.post('/api/tokens/change')
.then(function (response) {
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
swal({
title: "Woohoo!",
title: 'Woohoo!',
text: 'Your token was changed successfully.',
type: "success"
}, function(){
type: 'success'
}, () => {
localStorage.token = response.data.token;
location.reload();
});
})
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.changePassword = function() {
panel.page.innerHTML = '';
var container = document.createElement('div');
container.className = "container";
container.className = 'container';
container.innerHTML = `
<h2 class="subtitle">Change your password</h2>
@ -569,56 +503,51 @@ panel.changePassword = function(){
panel.page.appendChild(container);
document.getElementById('sendChangePassword').addEventListener('click', function(){
document.getElementById('sendChangePassword').addEventListener('click', () => {
if (document.getElementById('password').value === document.getElementById('passwordConfirm').value) {
panel.sendNewPassword(document.getElementById('password').value);
} else {
swal({
title: "Password mismatch!",
title: 'Password mismatch!',
text: 'Your passwords do not match, please try again.',
type: "error"
}, function() {
type: 'error'
}, () => {
panel.changePassword();
});
}
});
}
};
panel.sendNewPassword = function(pass) {
axios.post('/api/password/change', { password: pass })
.then(function (response) {
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
else return swal("An error ocurred", response.data.description, "error");
else return swal('An error ocurred', response.data.description, 'error');
}
swal({
title: "Woohoo!",
title: 'Woohoo!',
text: 'Your password was changed successfully.',
type: "success"
}, function(){
type: 'success'
}, () => {
location.reload();
});
})
})
.catch(function (error) {
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
console.log(error);
});
}
};
panel.setActiveMenu = function(item) {
var menu = document.getElementById('menu');
var items = menu.getElementsByTagName('a');
for(var i = 0; i < items.length; i++)
items[i].className = "";
for (var i = 0; i < items.length; i++) { items[i].className = ''; }
item.className = 'is-active';
}
};
window.onload = function() {
panel.preparePage();
}
};

View File

@ -3,95 +3,89 @@ var upload = {};
upload.isPrivate = true;
upload.token = localStorage.token;
upload.maxFileSize;
// add the album var to the upload so we can store the album id in there
// Add the album var to the upload so we can store the album id in there
upload.album;
upload.myDropzone;
upload.checkIfPublic = function() {
axios.get('/api/check')
.then(function (response) {
.then(response => {
upload.isPrivate = response.data.private;
upload.maxFileSize = response.data.maxFileSize;
upload.preparePage();
})
.catch(function (error) {
swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
return console.log(error);
});
}
};
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)
reloadOnError = false;
axios.post('/api/tokens/verify', {
token: token
})
.then(function (response) {
if (reloadOnError === undefined) { reloadOnError = false; }
axios.post('/api/tokens/verify', { token: token })
.then(response => {
if (response.data.success === false) {
swal({
title: "An error ocurred",
title: 'An error ocurred',
text: response.data.description,
type: "error"
}, function(){
type: 'error'
}, () => {
if (reloadOnError) {
localStorage.removeItem("token");
localStorage.removeItem('token');
location.reload();
}
})
});
return;
}
localStorage.token = token;
upload.token = token;
return upload.prepareUpload();
})
.catch(function (error) {
swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(error => {
swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
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
if (upload.token) {
var select = document.getElementById('albumSelect');
select.addEventListener('change', function() {
select.addEventListener('change', () => {
upload.album = select.value;
});
axios.get('/api/albums', { headers: { token: upload.token } })
.then(function(res) {
.then(res => {
var albums = res.data.albums;
// if the user doesn't have any albums we don't really need to display
// If the user doesn't have any albums we don't really need to display
// an album selection
if (albums.length === 0) return;
// loop through the albums and create an option for each album
// Loop through the albums and create an option for each album
for (var i = 0; i < albums.length; i++) {
var opt = document.createElement('option');
opt.value = albums[i].id;
opt.innerHTML = albums[i].name;
select.appendChild(opt);
}
// display the album selection
// Display the album selection
document.getElementById('albumDiv').style.display = 'block';
})
.catch(function(e) {
swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
.catch(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');
@ -99,17 +93,15 @@ upload.prepareUpload = function(){
div.innerHTML = 'Click here or drag and drop files';
div.style.display = 'flex';
document.getElementById('maxFileSize').innerHTML = 'Maximum upload size per file is ' + upload.maxFileSize;
document.getElementById('maxFileSize').innerHTML = `Maximum upload size per file is ${upload.maxFileSize}`;
document.getElementById('loginToUpload').style.display = 'none';
if(upload.token === undefined)
document.getElementById('loginLinkText').innerHTML = 'Create an account and keep track of your uploads';
if (upload.token === undefined) { document.getElementById('loginLinkText').innerHTML = 'Create an account and keep track of your uploads'; }
document.getElementById('uploadContainer').appendChild(div);
upload.prepareDropzone();
}
};
upload.prepareDropzone = function() {
var previewNode = document.querySelector('#template');
@ -128,31 +120,28 @@ upload.prepareDropzone = function(){
createImageThumbnails: false,
maxFiles: 1000,
autoProcessQueue: true,
headers: {
'token': upload.token
},
headers: { token: upload.token },
init: function() {
upload.myDropzone = this;
this.on('addedfile', function(file) {
this.on('addedfile', file => {
document.getElementById('uploads').style.display = 'block';
});
// add the selected albumid, if an album is selected, as a header
this.on('sending', function(file, xhr) {
// Add the selected albumid, if an album is selected, as a header
this.on('sending', (file, xhr) => {
if (upload.album) {
xhr.setRequestHeader('albumid', upload.album)
xhr.setRequestHeader('albumid', upload.album);
}
});
}
});
// Update the total progress bar
dropzone.on('uploadprogress', function(file, progress) {
dropzone.on('uploadprogress', (file, progress) => {
file.previewElement.querySelector('.progress').setAttribute('value', progress);
file.previewElement.querySelector('.progress').innerHTML = progress + '%';
file.previewElement.querySelector('.progress').innerHTML = `${progress}%`;
});
dropzone.on('success', function(file, response) {
dropzone.on('success', (file, response) => {
// Handle the responseText here. For example, add the text to the preview element:
if (response.success === false) {
@ -169,43 +158,42 @@ upload.prepareDropzone = function(){
file.previewTemplate.querySelector('.link').appendChild(a);
file.previewTemplate.querySelector('.progress').style.display = 'none';
});
upload.prepareShareX();
}
};
upload.prepareShareX = function() {
if (upload.token) {
var sharex_element = document.getElementById("ShareX");
var sharex_file = "{\r\n\
\"Name\": \"" + location.hostname + "\",\r\n\
\"DestinationType\": \"ImageUploader, FileUploader\",\r\n\
\"RequestType\": \"POST\",\r\n\
\"RequestURL\": \"" + location.origin + "/api/upload\",\r\n\
\"FileFormName\": \"files[]\",\r\n\
\"Headers\": {\r\n\
\"token\": \"" + upload.token + "\"\r\n\
var sharex_element = document.getElementById('ShareX');
var sharex_file = `{\r\n\
"Name": "${location.hostname}",\r\n\
"DestinationType": "ImageUploader, FileUploader",\r\n\
"RequestType": "POST",\r\n\
"RequestURL": "${location.origin}/api/upload",\r\n\
"FileFormName": "files[]",\r\n\
"Headers": {\r\n\
"token": "${upload.token}"\r\n\
},\r\n\
\"ResponseType\": \"Text\",\r\n\
\"URL\": \"$json:files[0].url$\",\r\n\
\"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("download", location.hostname + ".sxcu");
}
"ResponseType": "Text",\r\n\
"URL": "$json:files[0].url$",\r\n\
"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('download', `${location.hostname}.sxcu`);
}
};
// Handle image paste event
window.addEventListener('paste', function(event) {
window.addEventListener('paste', event => {
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) {
var item = items[index];
if (item.kind === 'file') {
var blob = item.getAsFile();
console.log(blob.type);
var file = new File([blob], "pasted-image."+blob.type.match(/(?:[^\/]*\/)([^;]*)/)[1]);
var file = new File([blob], `pasted-image.${blob.type.match(/(?:[^\/]*\/)([^;]*)/)[1]}`);
file.type = blob.type;
console.log(file);
upload.myDropzone.addFile(file);

View File

@ -15,7 +15,7 @@
<meta name="apple-mobile-web-app-title" content="lolisafe">
<meta name="application-name" content="lolisafe">
<meta name="msapplication-config" content="https://safe.fiery.me/images/icons/browserconfig.xml?v=ZqYs7M3fG4">
<meta name="theme-color" content="#ffffff">
<meta name="theme-color" content="#232629">
<meta property="og:url" content="https://safe.fiery.me" />
<meta property="og:type" content="website" />