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

2
.gitignore vendored
View File

@ -11,4 +11,4 @@ pages/custom/**
migrate.js
yarn.lock
package-lock.json
.vscode/
.vscode/

View File

@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

View File

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

View File

@ -12,11 +12,11 @@ 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('./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`);
safe.use(helmet());
safe.set('trust proxy', 1);

View File

@ -38,16 +38,17 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<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>
<script type="text/javascript" src="/js/auth.js"></script>
<style type="text/css">
/** Based on KDE Breeze Dark **/
section#login {
background-color: #232629;
}
</style>
</head>
<body>
<style type="text/css">
section#login {
background-color: #f5f6f8;
}
</style>
<section id='login' class="hero is-fullheight">
<div class="hero-body">
<div class="container">

View File

@ -38,7 +38,90 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<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>
<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

@ -41,7 +41,7 @@ section#home div#dropzone {
padding-left: .75em;
padding-right: .75em;
text-align: center;
cursor: pointer;
cursor: pointer;
}
section#home div#uploads, section#home p#tokenContainer, section#home a#panel { display: none; }
@ -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){
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) {
.then(response => {
if (response.data.success === false) { return swal('Error', response.data.description, 'error'); }
if(response.data.success === false)
return swal('Error', response.data.description, 'error');
localStorage.token = response.data.token;
window.location = '/dashboard';
localStorage.token = response.data.token;
window.location = '/dashboard';
})
.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);
});
};
})
.catch(function (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.verify = function() {
page.token = localStorage.token;
if(page.token === undefined) return;
if (page.token === undefined) return;
axios.post('/api/tokens/verify', {
token: page.token
})
.then(function (response) {
axios.post('/api/tokens/verify', { token: page.token })
.then(response => {
if (response.data.success === false) { return swal('Error', response.data.description, 'error'); }
if(response.data.success === false)
return swal('Error', response.data.description, 'error');
window.location = '/dashboard';
window.location = '/dashboard';
})
.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);
});
};
})
.catch(function (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 () {
window.onload = function() {
page.verify();
}
};

View File

@ -1,104 +1,95 @@
let panel = {}
let panel = {};
panel.page;
panel.username;
panel.token = localStorage.token;
panel.filesView = localStorage.filesView;
panel.preparePage = function(){
if(!panel.token) return window.location = '/auth';
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;
panel.verifyToken = function(token, reloadOnError) {
if (reloadOnError === undefined) { reloadOnError = false; }
axios.post('/api/tokens/verify', {
token: token
})
.then(function (response) {
axios.post('/api/tokens/verify', { token: token })
.then(response => {
if (response.data.success === false) {
swal({
title: 'An error ocurred',
text: response.data.description,
type: 'error'
}, () => {
if (reloadOnError) {
localStorage.removeItem('token');
location.location = '/auth';
}
});
return;
}
if(response.data.success === false){
swal({
title: "An error ocurred",
text: response.data.description,
type: "error"
}, function(){
if(reloadOnError){
localStorage.removeItem("token");
location.location = '/auth';
}
})
return;
}
axios.defaults.headers.common.token = token;
localStorage.token = token;
panel.token = token;
panel.username = response.data.username;
return panel.prepareDashboard();
})
.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);
});
};
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");
console.log(error);
});
}
panel.prepareDashboard = function(){
panel.prepareDashboard = function() {
panel.page = document.getElementById('page');
document.getElementById('auth').style.display = 'none';
document.getElementById('dashboard').style.display = 'block';
document.getElementById('itemUploads').addEventListener('click', function(){
document.getElementById('itemUploads').addEventListener('click', function() {
panel.setActiveMenu(this);
});
document.getElementById('itemManageGallery').addEventListener('click', function(){
document.getElementById('itemManageGallery').addEventListener('click', function() {
panel.setActiveMenu(this);
});
document.getElementById('itemTokens').addEventListener('click', function(){
document.getElementById('itemTokens').addEventListener('click', function() {
panel.setActiveMenu(this);
});
document.getElementById('itemPassword').addEventListener('click', function(){
document.getElementById('itemPassword').addEventListener('click', function() {
panel.setActiveMenu(this);
});
document.getElementById('itemLogout').innerHTML = `Logout ( ${panel.username} )`;
panel.getAlbumsSidebar();
}
};
panel.logout = function(){
localStorage.removeItem("token");
panel.logout = function() {
localStorage.removeItem('token');
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}`;
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) {
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");
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');
}
var prevPage = 0;
var nextPage = page + 1;
if(response.data.files.length < 25)
nextPage = page;
if(page > 0) prevPage = page - 1;
if (response.data.files.length < 25) { nextPage = page; }
if (page > 0) prevPage = page - 1;
panel.page.innerHTML = '';
var container = document.createElement('div');
@ -120,10 +111,9 @@ panel.getUploads = function(album = undefined, page = undefined){
</span>
</a>
</div>
</div>`
if(panel.filesView === 'thumbs'){
</div>`;
if (panel.filesView === 'thumbs') {
container.innerHTML = `
${pagination}
<hr>
@ -137,23 +127,15 @@ panel.getUploads = function(album = undefined, page = undefined){
panel.page.appendChild(container);
var table = document.getElementById('table');
for(var item of response.data.files){
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{
} else {
var albumOrUser = 'Album';
if(panel.username === 'root')
albumOrUser = 'User';
if (panel.username === 'root') { albumOrUser = 'User'; }
container.innerHTML = `
${pagination}
@ -178,17 +160,15 @@ panel.getUploads = function(album = undefined, page = undefined){
panel.page.appendChild(container);
var table = document.getElementById('table');
for(var item of response.data.files){
for (var item of response.data.files) {
var tr = document.createElement('tr');
var displayAlbumOrUser = item.album;
if(panel.username === 'root'){
if (panel.username === 'root') {
displayAlbumOrUser = '';
if(item.username !== undefined)
displayAlbumOrUser = item.username;
if (item.username !== undefined) { displayAlbumOrUser = item.username; }
}
tr.innerHTML = `
<tr>
<th><a href="${item.file}" target="_blank">${item.file}</a></th>
@ -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");
console.log(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){
panel.setFilesView = function(view, album, page) {
localStorage.filesView = view;
panel.filesView = view;
panel.getUploads(album, page);
}
};
panel.deleteFile = function(id){
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) {
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");
() => {
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');
}
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) {
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");
panel.getAlbums = function() {
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');
}
panel.page.innerHTML = '';
var container = document.createElement('div');
container.className = "container";
container.className = 'container';
container.innerHTML = `
<h2 class="subtitle">Create new album</h2>
@ -295,8 +266,7 @@ panel.getAlbums = function(){
panel.page.appendChild(container);
var table = document.getElementById('table');
for(var item of response.data.albums){
for (var item of response.data.albums) {
var tr = document.createElement('tr');
tr.innerHTML = `
<tr>
@ -322,182 +292,153 @@ 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");
console.log(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){
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) {
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");
return;
}
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");
console.log(error);
});
});
}
panel.deleteAlbum = function(id){
swal({
title: "Are you sure?",
text: "This won't delete your files, only the album!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#ff3860",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function(){
axios.post('/api/albums/delete', {
id: id
})
.then(function (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");
.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');
return;
}
swal("Deleted!", "Your album has been deleted.", "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.submitAlbum = function(){
axios.post('/api/albums', {
name: document.getElementById('albumName').value
})
.then(function (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");
}
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");
console.log(error);
});
};
}
panel.deleteAlbum = function(id) {
swal({
title: 'Are you sure?',
text: "This won't delete your files, only the album!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#ff3860',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false
},
() => {
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');
}
panel.getAlbumsSidebar = function(){
axios.get('/api/albums/sidebar')
.then(function (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");
}
var albumsContainer = document.getElementById('albumsContainer');
albumsContainer.innerHTML = '';
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;
a.innerHTML = album.name;
a.addEventListener('click', function(){
panel.getAlbum(this);
swal('Deleted!', 'Your album has been deleted.', 'success');
panel.getAlbumsSidebar();
panel.getAlbums();
})
.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);
});
}
);
};
li.appendChild(a);
albumsContainer.appendChild(li);
}
panel.submitAlbum = function() {
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');
}
swal('Woohoo!', 'Album was added successfully', 'success');
panel.getAlbumsSidebar();
panel.getAlbums();
})
.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);
});
};
})
.catch(function (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(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');
}
}
var albumsContainer = document.getElementById('albumsContainer');
albumsContainer.innerHTML = '';
panel.getAlbum = function(item){
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;
a.innerHTML = album.name;
a.addEventListener('click', function() {
panel.getAlbum(this);
});
li.appendChild(a);
albumsContainer.appendChild(li);
}
})
.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(){
};
panel.changeToken = function() {
axios.get('/api/tokens')
.then(function (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");
}
.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');
}
panel.page.innerHTML = '';
var container = document.createElement('div');
container.className = "container";
container.innerHTML = `
panel.page.innerHTML = '';
var container = document.createElement('div');
container.className = 'container';
container.innerHTML = `
<h2 class="subtitle">Manage your token</h2>
<label class="label">Your current token:</label>
@ -507,52 +448,45 @@ panel.changeToken = function(){
</p>
`;
panel.page.appendChild(container);
panel.page.appendChild(container);
document.getElementById('getNewToken').addEventListener('click', function(){
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");
console.log(error);
});
}
panel.getNewToken = function(){
axios.post('/api/tokens/change')
.then(function (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");
}
swal({
title: "Woohoo!",
text: 'Your token was changed successfully.',
type: "success"
}, function(){
localStorage.token = response.data.token;
location.reload();
document.getElementById('getNewToken').addEventListener('click', () => {
panel.getNewToken();
});
})
.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);
});
};
})
.catch(function (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(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');
}
}
panel.changePassword = function(){
swal({
title: 'Woohoo!',
text: 'Your token was changed successfully.',
type: 'success'
}, () => {
localStorage.token = response.data.token;
location.reload();
});
})
.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!",
text: 'Your passwords do not match, please try again.',
type: "error"
}, function() {
title: 'Password mismatch!',
text: 'Your passwords do not match, please try again.',
type: 'error'
}, () => {
panel.changePassword();
});
}
});
}
};
panel.sendNewPassword = function(pass){
panel.sendNewPassword = function(pass) {
axios.post('/api/password/change', { password: pass })
.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');
}
axios.post('/api/password/change', {password: pass})
.then(function (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");
}
swal({
title: "Woohoo!",
text: 'Your password was changed successfully.',
type: "success"
}, function(){
location.reload();
swal({
title: 'Woohoo!',
text: 'Your password was changed successfully.',
type: 'success'
}, () => {
location.reload();
});
})
.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);
});
};
})
.catch(function (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){
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 () {
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(){
upload.checkIfPublic = function() {
axios.get('/api/check')
.then(function (response) {
upload.isPrivate= response.data.private;
upload.maxFileSize = response.data.maxFileSize;
upload.preparePage();
.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.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) {
upload.verifyToken = function(token, reloadOnError) {
if (reloadOnError === undefined) { reloadOnError = false; }
if(response.data.success === false){
axios.post('/api/tokens/verify', { token: token })
.then(response => {
if (response.data.success === false) {
swal({
title: "An error ocurred",
text: response.data.description,
type: "error"
}, function(){
if(reloadOnError){
localStorage.removeItem("token");
location.reload();
}
})
return;
title: 'An error ocurred',
text: response.data.description,
type: 'error'
}, () => {
if (reloadOnError) {
localStorage.removeItem('token');
location.reload();
}
});
return;
}
localStorage.token = token;
upload.token = token;
return upload.prepareUpload();
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(){
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) {
var albums = res.data.albums;
// 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
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
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");
return console.log(e);
})
axios.get('/api/albums', { headers: { token: upload.token } })
.then(res => {
var albums = res.data.albums;
// 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
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
document.getElementById('albumDiv').style.display = 'block';
})
.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,25 +93,23 @@ 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(){
upload.prepareDropzone = function() {
var previewNode = document.querySelector('#template');
previewNode.id = '';
var previewTemplate = previewNode.parentNode.innerHTML;
previewNode.parentNode.removeChild(previewNode);
var dropzone = new Dropzone('div#dropzone', {
var dropzone = new Dropzone('div#dropzone', {
url: '/api/upload',
paramName: 'files[]',
maxFilesize: upload.maxFileSize.slice(0, -2),
@ -128,34 +120,31 @@ 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){
if (response.success === false) {
var span = document.createElement('span');
span.innerHTML = response.description;
file.previewTemplate.querySelector('.link').appendChild(span);
@ -167,45 +156,44 @@ upload.prepareDropzone = function(){
a.target = '_blank';
a.innerHTML = response.files[0].url;
file.previewTemplate.querySelector('.link').appendChild(a);
file.previewTemplate.querySelector('.progress').style.display = 'none';
});
upload.prepareShareX();
}
};
upload.prepareShareX = function(){
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) {
// Handle image paste 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);
@ -213,7 +201,7 @@ window.addEventListener('paste', function(event) {
}
});
window.onload = function () {
window.onload = function() {
upload.checkIfPublic();
};

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" />