mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 00:46:22 +00:00
7991a63315
NOTICE: Please update your config.js. Use config.sample.js as the template. There were a couple of renames and restructures. * Album zipper API route will now internally save its state when it's generating zip files, and any subsequent requests will silently be "postponed" until the first spawned task is finished. This will guarantee that there are no multiple zipping tasks for the same album. The method may seem a bit hackish though. * All instances of console.log(error) were replaced with console.error(error). This will guarantee that any error goes to stderr instead of stdout. * Deleting file by names will now properly remove successful files from the textarea. There was a logic flaw. * Failure to generate thumbnails will no longer print the full stack, but instead only the error message. It will also then symlink a template image from /public/images/unavailable.png (it's only a simple image that says that it failed to generate thumbnail). This haven't been tested in Windows machines, but it'll probably work fine. I thought of adding a new column to files table which will store information whether the thumbnail generation is sucessful or not, but oh well, I'll go with this method for now.
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
/* global swal, axios */
|
|
|
|
const page = {
|
|
// user token
|
|
token: localStorage.token
|
|
}
|
|
|
|
page.do = async dest => {
|
|
const user = document.getElementById('user').value
|
|
const pass = document.getElementById('pass').value
|
|
|
|
if (!user) {
|
|
return swal('Error', 'You need to specify a username', 'error')
|
|
}
|
|
|
|
if (!pass) {
|
|
return swal('Error', 'You need to specify a username', 'error')
|
|
}
|
|
|
|
const response = await axios.post(`api/${dest}`, {
|
|
username: user,
|
|
password: pass
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
|
})
|
|
if (!response) { return }
|
|
|
|
if (response.data.success === false) {
|
|
return swal('Error', response.data.description, 'error')
|
|
}
|
|
|
|
localStorage.token = response.data.token
|
|
window.location = 'dashboard'
|
|
}
|
|
|
|
page.verify = async () => {
|
|
if (!page.token) { return }
|
|
|
|
const response = await axios.post('api/tokens/verify', {
|
|
token: page.token
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
|
})
|
|
if (!response) { return }
|
|
|
|
if (response.data.success === false) {
|
|
return swal('Error', response.data.description, 'error')
|
|
}
|
|
|
|
window.location = 'dashboard'
|
|
}
|
|
|
|
window.onload = () => {
|
|
page.verify()
|
|
|
|
document.body.addEventListener('keydown', event => {
|
|
event = event || window.event
|
|
if (!event) { return }
|
|
const id = event.target.id
|
|
if (!['user', 'pass'].includes(id)) { return }
|
|
if (event.keyCode === 13 || event.which === 13) { page.do('login') }
|
|
})
|
|
}
|