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 migrate.js
yarn.lock yarn.lock
package-lock.json 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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 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' }, connection: { filename: './database/db' },
useNullAsDefault: true useNullAsDefault: true
} }
} };

View File

@ -12,11 +12,11 @@ const safe = express();
require('./database/db.js')(db); require('./database/db.js')(db);
fs.existsSync('./pages/custom' ) || fs.mkdirSync('./pages/custom'); fs.existsSync('./pages/custom') || fs.mkdirSync('./pages/custom');
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder); fs.existsSync(`./${config.logsFolder}`) || fs.mkdirSync(`./${ config.logsFolder}`);
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder); 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}/thumbs`) || fs.mkdirSync(`./${config.uploads.folder }/thumbs`);
fs.existsSync('./' + config.uploads.folder + '/zips') || fs.mkdirSync('./' + config.uploads.folder + '/zips') fs.existsSync(`./${config.uploads.folder }/zips`) || fs.mkdirSync(`./${config.uploads.folder}/zips`);
safe.use(helmet()); safe.use(helmet());
safe.set('trust proxy', 1); 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/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://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="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> </head>
<body> <body>
<style type="text/css">
section#login {
background-color: #f5f6f8;
}
</style>
<section id='login' class="hero is-fullheight"> <section id='login' class="hero is-fullheight">
<div class="hero-body"> <div class="hero-body">
<div class="container"> <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/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://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="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> </head>
<body> <body>

View File

@ -41,7 +41,7 @@ section#home div#dropzone {
padding-left: .75em; padding-left: .75em;
padding-right: .75em; padding-right: .75em;
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
} }
section#home div#uploads, section#home p#tokenContainer, section#home a#panel { display: none; } 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; text-align: center;
margin-bottom: 10px; 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 = {}; var page = {};
page.do = function(dest){ page.do = function(dest) {
var user = document.getElementById('user').value; var user = document.getElementById('user').value;
var pass = document.getElementById('pass').value; var pass = document.getElementById('pass').value;
if(user === undefined || user === null || user === '') if (user === undefined || user === null || user === '') { return swal('Error', 'You need to specify a username', 'error'); }
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(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, username: user,
password: pass password: pass
}) })
.then(function (response) { .then(response => {
if (response.data.success === false) { return swal('Error', response.data.description, 'error'); }
if(response.data.success === false) localStorage.token = response.data.token;
return swal('Error', response.data.description, 'error'); window.location = '/dashboard';
})
localStorage.token = response.data.token; .catch(error => {
window.location = '/dashboard'; 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() {
.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.token = localStorage.token; page.token = localStorage.token;
if(page.token === undefined) return; if (page.token === undefined) return;
axios.post('/api/tokens/verify', { axios.post('/api/tokens/verify', { token: page.token })
token: page.token .then(response => {
}) if (response.data.success === false) { return swal('Error', response.data.description, 'error'); }
.then(function (response) {
if(response.data.success === false) window.location = '/dashboard';
return swal('Error', response.data.description, 'error'); })
.catch(error => {
window.location = '/dashboard'; 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() {
.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 () {
page.verify(); page.verify();
} };

View File

@ -1,104 +1,95 @@
let panel = {} let panel = {};
panel.page; panel.page;
panel.username; panel.username;
panel.token = localStorage.token; panel.token = localStorage.token;
panel.filesView = localStorage.filesView; 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) { reloadOnError = false; }
reloadOnError = false;
axios.post('/api/tokens/verify', { axios.post('/api/tokens/verify', { token: token })
token: token .then(response => {
}) if (response.data.success === false) {
.then(function (response) { 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){ axios.defaults.headers.common.token = token;
swal({ localStorage.token = token;
title: "An error ocurred", panel.token = token;
text: response.data.description, panel.username = response.data.username;
type: "error" return panel.prepareDashboard();
}, function(){ })
if(reloadOnError){ .catch(error => {
localStorage.removeItem("token"); return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
location.location = '/auth'; console.log(error);
} });
}) };
return;
}
axios.defaults.headers.common['token'] = token; panel.prepareDashboard = function() {
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.page = document.getElementById('page'); panel.page = document.getElementById('page');
document.getElementById('auth').style.display = 'none'; document.getElementById('auth').style.display = 'none';
document.getElementById('dashboard').style.display = 'block'; document.getElementById('dashboard').style.display = 'block';
document.getElementById('itemUploads').addEventListener('click', function(){ document.getElementById('itemUploads').addEventListener('click', function() {
panel.setActiveMenu(this); panel.setActiveMenu(this);
}); });
document.getElementById('itemManageGallery').addEventListener('click', function(){ document.getElementById('itemManageGallery').addEventListener('click', function() {
panel.setActiveMenu(this); panel.setActiveMenu(this);
}); });
document.getElementById('itemTokens').addEventListener('click', function(){ document.getElementById('itemTokens').addEventListener('click', function() {
panel.setActiveMenu(this); panel.setActiveMenu(this);
}); });
document.getElementById('itemPassword').addEventListener('click', function(){ document.getElementById('itemPassword').addEventListener('click', function() {
panel.setActiveMenu(this); panel.setActiveMenu(this);
}); });
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}`;
if (album !== undefined) { url = `/api/album/${album}/${page}`; }
let url = '/api/uploads/' + page axios.get(url).then(response => {
if(album !== undefined) if (response.data.success === false) {
url = '/api/album/' + album + '/' + page 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(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 prevPage = 0; var prevPage = 0;
var nextPage = page + 1; var nextPage = page + 1;
if(response.data.files.length < 25) if (response.data.files.length < 25) { nextPage = page; }
nextPage = page;
if (page > 0) prevPage = page - 1;
if(page > 0) prevPage = page - 1;
panel.page.innerHTML = ''; panel.page.innerHTML = '';
var container = document.createElement('div'); var container = document.createElement('div');
@ -120,10 +111,9 @@ panel.getUploads = function(album = undefined, page = undefined){
</span> </span>
</a> </a>
</div> </div>
</div>` </div>`;
if(panel.filesView === 'thumbs'){
if (panel.filesView === 'thumbs') {
container.innerHTML = ` container.innerHTML = `
${pagination} ${pagination}
<hr> <hr>
@ -137,23 +127,15 @@ panel.getUploads = function(album = undefined, page = undefined){
panel.page.appendChild(container); panel.page.appendChild(container);
var table = document.getElementById('table'); var table = document.getElementById('table');
for(var item of response.data.files){ for (var item of response.data.files) {
var div = document.createElement('div'); var div = document.createElement('div');
div.className = "column is-2"; div.className = 'column is-2';
if(item.thumb !== undefined) 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.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); table.appendChild(div);
} }
} else {
}else{
var albumOrUser = 'Album'; var albumOrUser = 'Album';
if(panel.username === 'root') if (panel.username === 'root') { albumOrUser = 'User'; }
albumOrUser = 'User';
container.innerHTML = ` container.innerHTML = `
${pagination} ${pagination}
@ -178,17 +160,15 @@ panel.getUploads = function(album = undefined, page = undefined){
panel.page.appendChild(container); panel.page.appendChild(container);
var table = document.getElementById('table'); 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 tr = document.createElement('tr');
var displayAlbumOrUser = item.album; var displayAlbumOrUser = item.album;
if(panel.username === 'root'){ if (panel.username === 'root') {
displayAlbumOrUser = ''; displayAlbumOrUser = '';
if(item.username !== undefined) if (item.username !== undefined) { displayAlbumOrUser = item.username; }
displayAlbumOrUser = item.username;
} }
tr.innerHTML = ` tr.innerHTML = `
<tr> <tr>
<th><a href="${item.file}" target="_blank">${item.file}</a></th> <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) { .catch(error => {
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);
}); });
};
} 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({
title: "Are you sure?", title: 'Are you sure?',
text: "You wont be able to recover the file!", text: 'You wont be able to recover the file!',
type: "warning", type: 'warning',
showCancelButton: true, showCancelButton: true,
confirmButtonColor: "#ff3860", confirmButtonColor: '#ff3860',
confirmButtonText: "Yes, delete it!", confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false closeOnConfirm: false
}, },
function(){ () => {
axios.post('/api/upload/delete', { id: id })
axios.post('/api/upload/delete', { .then(response => {
id: id if (response.data.success === false) {
}) if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
.then(function (response) { else return swal('An error ocurred', response.data.description, 'error');
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(); panel.getUploads();
return;
}) })
.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"); 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);
}); });
}
}
); );
} };
panel.getAlbums = function(){ panel.getAlbums = function() {
axios.get('/api/albums').then(response => {
axios.get('/api/albums').then(function (response) { if (response.data.success === false) {
if(response.data.success === false){ if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
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 = ''; panel.page.innerHTML = '';
var container = document.createElement('div'); var container = document.createElement('div');
container.className = "container"; container.className = 'container';
container.innerHTML = ` container.innerHTML = `
<h2 class="subtitle">Create new album</h2> <h2 class="subtitle">Create new album</h2>
@ -295,8 +266,7 @@ panel.getAlbums = function(){
panel.page.appendChild(container); panel.page.appendChild(container);
var table = document.getElementById('table'); var table = document.getElementById('table');
for(var item of response.data.albums){ for (var item of response.data.albums) {
var tr = document.createElement('tr'); var tr = document.createElement('tr');
tr.innerHTML = ` tr.innerHTML = `
<tr> <tr>
@ -322,182 +292,153 @@ panel.getAlbums = function(){
table.appendChild(tr); table.appendChild(tr);
} }
document.getElementById('submitAlbum').addEventListener('click', function(){ document.getElementById('submitAlbum').addEventListener('click', () => {
panel.submitAlbum(); panel.submitAlbum();
}); });
}) })
.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"); 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);
}); });
};
} panel.renameAlbum = function(id) {
panel.renameAlbum = function(id){
swal({ swal({
title: "Rename album", title: 'Rename album',
text: "New name you want to give the album:", text: 'New name you want to give the album:',
type: "input", type: 'input',
showCancelButton: true, showCancelButton: true,
closeOnConfirm: false, closeOnConfirm: false,
animation: "slide-from-top", animation: 'slide-from-top',
inputPlaceholder: "My super album" inputPlaceholder: 'My super album'
},function(inputValue){ }, inputValue => {
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', {
id: id, id: id,
name: inputValue name: inputValue
}) })
.then(function (response) { .then(response => {
if (response.data.success === false) {
if(response.data.success === false){ if (response.data.description === 'No token provided') return panel.verifyToken(panel.token);
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 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 swal("An error ocurred", response.data.description, "error"); return;
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");
} }
swal("Deleted!", "Your album has been deleted.", "success"); swal('Success!', `Your album was renamed to: ${inputValue}`, 'success');
panel.getAlbumsSidebar(); panel.getAlbumsSidebar();
panel.getAlbums(); panel.getAlbums();
return;
}) })
.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"); 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);
}); });
}
);
}
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(){ swal('Deleted!', 'Your album has been deleted.', 'success');
panel.getAlbumsSidebar();
axios.get('/api/albums/sidebar') panel.getAlbums();
.then(function (response) { })
if(response.data.success === false){ .catch(error => {
if(response.data.description === 'No token provided') return panel.verifyToken(panel.token); return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
else return swal("An error ocurred", response.data.description, "error"); console.log(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);
}); });
}
);
};
li.appendChild(a); panel.submitAlbum = function() {
albumsContainer.appendChild(li); 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);
});
};
}) panel.getAlbumsSidebar = function() {
.catch(function (error) { axios.get('/api/albums/sidebar')
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); .then(response => {
console.log(error); 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.setActiveMenu(item);
panel.getUploads(item.id); panel.getUploads(item.id);
} };
panel.changeToken = function(){
panel.changeToken = function() {
axios.get('/api/tokens') axios.get('/api/tokens')
.then(function (response) { .then(response => {
if(response.data.success === false){ if (response.data.success === false) {
if(response.data.description === 'No token provided') return panel.verifyToken(panel.token); 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 = ''; panel.page.innerHTML = '';
var container = document.createElement('div'); var container = document.createElement('div');
container.className = "container"; container.className = 'container';
container.innerHTML = ` container.innerHTML = `
<h2 class="subtitle">Manage your token</h2> <h2 class="subtitle">Manage your token</h2>
<label class="label">Your current token:</label> <label class="label">Your current token:</label>
@ -507,52 +448,45 @@ panel.changeToken = function(){
</p> </p>
`; `;
panel.page.appendChild(container); panel.page.appendChild(container);
document.getElementById('getNewToken').addEventListener('click', function(){ document.getElementById('getNewToken').addEventListener('click', () => {
panel.getNewToken(); 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();
}) })
.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() {
.catch(function (error) { axios.post('/api/tokens/change')
return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); .then(response => {
console.log(error); 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!',
panel.changePassword = function(){ 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 = ''; panel.page.innerHTML = '';
var container = document.createElement('div'); var container = document.createElement('div');
container.className = "container"; container.className = 'container';
container.innerHTML = ` container.innerHTML = `
<h2 class="subtitle">Change your password</h2> <h2 class="subtitle">Change your password</h2>
@ -569,56 +503,51 @@ panel.changePassword = function(){
panel.page.appendChild(container); panel.page.appendChild(container);
document.getElementById('sendChangePassword').addEventListener('click', function(){ document.getElementById('sendChangePassword').addEventListener('click', () => {
if (document.getElementById('password').value === document.getElementById('passwordConfirm').value) { if (document.getElementById('password').value === document.getElementById('passwordConfirm').value) {
panel.sendNewPassword(document.getElementById('password').value); panel.sendNewPassword(document.getElementById('password').value);
} else { } else {
swal({ swal({
title: "Password mismatch!", title: 'Password mismatch!',
text: 'Your passwords do not match, please try again.', text: 'Your passwords do not match, please try again.',
type: "error" type: 'error'
}, function() { }, () => {
panel.changePassword(); 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}) swal({
.then(function (response) { title: 'Woohoo!',
text: 'Your password was changed successfully.',
if(response.data.success === false){ type: 'success'
if(response.data.description === 'No token provided') return panel.verifyToken(panel.token); }, () => {
else return swal("An error ocurred", response.data.description, "error"); location.reload();
} });
swal({
title: "Woohoo!",
text: 'Your password was changed successfully.',
type: "success"
}, function(){
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.setActiveMenu = function(item) {
.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){
var menu = document.getElementById('menu'); var menu = document.getElementById('menu');
var items = menu.getElementsByTagName('a'); var items = menu.getElementsByTagName('a');
for(var i = 0; i < items.length; i++) for (var i = 0; i < items.length; i++) { 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

@ -3,95 +3,89 @@ var upload = {};
upload.isPrivate = true; upload.isPrivate = true;
upload.token = localStorage.token; upload.token = localStorage.token;
upload.maxFileSize; 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.album;
upload.myDropzone; upload.myDropzone;
upload.checkIfPublic = function(){ upload.checkIfPublic = function() {
axios.get('/api/check') axios.get('/api/check')
.then(function (response) { .then(response => {
upload.isPrivate= response.data.private; upload.isPrivate = response.data.private;
upload.maxFileSize = response.data.maxFileSize; upload.maxFileSize = response.data.maxFileSize;
upload.preparePage(); upload.preparePage();
}) })
.catch(function (error) { .catch(error => {
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(error); return console.log(error);
}); });
} };
upload.preparePage = function(){ 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) { reloadOnError = false; }
reloadOnError = false;
axios.post('/api/tokens/verify', {
token: token
})
.then(function (response) {
if(response.data.success === false){ axios.post('/api/tokens/verify', { token: token })
.then(response => {
if (response.data.success === false) {
swal({ swal({
title: "An error ocurred", title: 'An error ocurred',
text: response.data.description, text: response.data.description,
type: "error" type: 'error'
}, function(){ }, () => {
if(reloadOnError){ if (reloadOnError) {
localStorage.removeItem("token"); localStorage.removeItem('token');
location.reload(); location.reload();
} }
}) });
return; return;
} }
localStorage.token = token; localStorage.token = token;
upload.token = token; upload.token = token;
return upload.prepareUpload(); return upload.prepareUpload();
}) })
.catch(function (error) { .catch(error => {
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(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
if (upload.token) { if (upload.token) {
var select = document.getElementById('albumSelect'); var select = document.getElementById('albumSelect');
select.addEventListener('change', function() { select.addEventListener('change', () => {
upload.album = select.value; upload.album = select.value;
}); });
axios.get('/api/albums', { headers: { token: upload.token }}) axios.get('/api/albums', { headers: { token: upload.token } })
.then(function(res) { .then(res => {
var albums = res.data.albums; 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 // an album selection
if (albums.length === 0) return; 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++) { for (var i = 0; i < albums.length; i++) {
var opt = document.createElement('option'); var opt = document.createElement('option');
opt.value = albums[i].id; opt.value = albums[i].id;
opt.innerHTML = albums[i].name; opt.innerHTML = albums[i].name;
select.appendChild(opt); select.appendChild(opt);
} }
// display the album selection // Display the album selection
document.getElementById('albumDiv').style.display = 'block'; document.getElementById('albumDiv').style.display = 'block';
}) })
.catch(function(e) { .catch(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');
@ -99,25 +93,23 @@ upload.prepareUpload = function(){
div.innerHTML = 'Click here or drag and drop files'; div.innerHTML = 'Click here or drag and drop files';
div.style.display = 'flex'; 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'; document.getElementById('loginToUpload').style.display = 'none';
if(upload.token === undefined) if (upload.token === undefined) { document.getElementById('loginLinkText').innerHTML = 'Create an account and keep track of your uploads'; }
document.getElementById('loginLinkText').innerHTML = 'Create an account and keep track of your uploads';
document.getElementById('uploadContainer').appendChild(div); document.getElementById('uploadContainer').appendChild(div);
upload.prepareDropzone(); upload.prepareDropzone();
};
} upload.prepareDropzone = function() {
upload.prepareDropzone = function(){
var previewNode = document.querySelector('#template'); var previewNode = document.querySelector('#template');
previewNode.id = ''; previewNode.id = '';
var previewTemplate = previewNode.parentNode.innerHTML; var previewTemplate = previewNode.parentNode.innerHTML;
previewNode.parentNode.removeChild(previewNode); previewNode.parentNode.removeChild(previewNode);
var dropzone = new Dropzone('div#dropzone', { var dropzone = new Dropzone('div#dropzone', {
url: '/api/upload', url: '/api/upload',
paramName: 'files[]', paramName: 'files[]',
maxFilesize: upload.maxFileSize.slice(0, -2), maxFilesize: upload.maxFileSize.slice(0, -2),
@ -128,34 +120,31 @@ upload.prepareDropzone = function(){
createImageThumbnails: false, createImageThumbnails: false,
maxFiles: 1000, maxFiles: 1000,
autoProcessQueue: true, autoProcessQueue: true,
headers: { headers: { token: upload.token },
'token': upload.token
},
init: function() { init: function() {
upload.myDropzone = this; upload.myDropzone = this;
this.on('addedfile', function(file) { this.on('addedfile', file => {
document.getElementById('uploads').style.display = 'block'; document.getElementById('uploads').style.display = 'block';
}); });
// 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', (file, xhr) => {
if (upload.album) { if (upload.album) {
xhr.setRequestHeader('albumid', upload.album) xhr.setRequestHeader('albumid', upload.album);
} }
}); });
} }
}); });
// Update the total progress bar // 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').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: // 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'); var span = document.createElement('span');
span.innerHTML = response.description; span.innerHTML = response.description;
file.previewTemplate.querySelector('.link').appendChild(span); file.previewTemplate.querySelector('.link').appendChild(span);
@ -167,45 +156,44 @@ upload.prepareDropzone = function(){
a.target = '_blank'; a.target = '_blank';
a.innerHTML = response.files[0].url; a.innerHTML = response.files[0].url;
file.previewTemplate.querySelector('.link').appendChild(a); file.previewTemplate.querySelector('.link').appendChild(a);
file.previewTemplate.querySelector('.progress').style.display = 'none'; file.previewTemplate.querySelector('.progress').style.display = 'none';
}); });
upload.prepareShareX(); upload.prepareShareX();
} };
upload.prepareShareX = function(){ upload.prepareShareX = function() {
if (upload.token) { if (upload.token) {
var sharex_element = document.getElementById("ShareX"); var sharex_element = document.getElementById('ShareX');
var sharex_file = "{\r\n\ var sharex_file = `{\r\n\
\"Name\": \"" + location.hostname + "\",\r\n\ "Name": "${location.hostname}",\r\n\
\"DestinationType\": \"ImageUploader, FileUploader\",\r\n\ "DestinationType": "ImageUploader, FileUploader",\r\n\
\"RequestType\": \"POST\",\r\n\ "RequestType": "POST",\r\n\
\"RequestURL\": \"" + location.origin + "/api/upload\",\r\n\ "RequestURL": "${location.origin}/api/upload",\r\n\
\"FileFormName\": \"files[]\",\r\n\ "FileFormName": "files[]",\r\n\
\"Headers\": {\r\n\ "Headers": {\r\n\
\"token\": \"" + upload.token + "\"\r\n\ "token": "${upload.token}"\r\n\
},\r\n\ },\r\n\
\"ResponseType\": \"Text\",\r\n\ "ResponseType": "Text",\r\n\
\"URL\": \"$json:files[0].url$\",\r\n\ "URL": "$json:files[0].url$",\r\n\
\"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', event => {
var items = (event.clipboardData || event.originalEvent.clipboardData).items; var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) { for (index in items) {
var item = items[index]; var item = items[index];
if (item.kind === 'file') { if (item.kind === 'file') {
var blob = item.getAsFile(); var blob = item.getAsFile();
console.log(blob.type); 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; file.type = blob.type;
console.log(file); console.log(file);
upload.myDropzone.addFile(file); upload.myDropzone.addFile(file);
@ -213,7 +201,7 @@ window.addEventListener('paste', function(event) {
} }
}); });
window.onload = function () { window.onload = function() {
upload.checkIfPublic(); upload.checkIfPublic();
}; };

View File

@ -15,7 +15,7 @@
<meta name="apple-mobile-web-app-title" content="lolisafe"> <meta name="apple-mobile-web-app-title" content="lolisafe">
<meta name="application-name" 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="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:url" content="https://safe.fiery.me" />
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />