`
table.appendChild(tr)
}
document.getElementById('submitAlbum').addEventListener('click', function () {
panel.submitAlbum(this)
})
})
.catch(error => {
console.log(error)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
}
panel.editAlbum = async id => {
const album = panel.albums.find(a => a.id === id)
if (!album) {
return swal('An error occurred!', 'Album with that ID could not be found.', 'error')
}
const div = document.createElement('div')
div.innerHTML = `
`
const value = await swal({
title: 'Edit album',
icon: 'info',
content: div,
buttons: {
cancel: true,
confirm: {
closeModal: false
}
}
})
if (!value) { return }
const response = await axios.post('api/albums/edit', {
id,
name: document.getElementById('_name').value,
download: document.getElementById('_download').checked,
public: document.getElementById('_public').checked,
requestLink: document.getElementById('_requestLink').checked
})
.catch(error => {
console.log(error)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
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') {
return swal.showInputError('That name is already in use!')
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
if (response.data.identifier) {
swal('Success!', `Your album's new identifier is: ${response.data.identifier}.`, 'success')
} else if (response.data.name !== album.name) {
swal('Success!', `Your album was renamed to: ${response.data.name}.`, 'success')
} else {
swal('Success!', 'Your album was edited!', 'success')
}
panel.getAlbumsSidebar()
panel.getAlbums()
}
panel.deleteAlbum = async id => {
const proceed = await swal({
title: 'Are you sure?',
text: 'This won\'t delete your files, only the album!',
icon: 'warning',
dangerMode: true,
buttons: {
cancel: true,
confirm: {
text: 'Yes, delete it!',
closeModal: false
},
purge: {
text: 'Umm, delete the files too please?',
value: 'purge',
className: 'swal-button--danger',
closeModal: false
}
}
})
if (!proceed) { return }
const response = await axios.post('api/albums/delete', {
id,
purge: proceed === 'purge'
})
.catch(error => {
console.log(error)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return panel.verifyToken(panel.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
swal('Deleted!', 'Your album has been deleted.', 'success')
panel.getAlbumsSidebar()
panel.getAlbums()
}
panel.submitAlbum = element => {
panel.isLoading(element, true)
axios.post('api/albums', {
name: document.getElementById('albumName').value
})
.then(response => {
panel.isLoading(element, false)
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return panel.verifyToken(panel.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
swal('Woohoo!', 'Album was added successfully', 'success')
panel.getAlbumsSidebar()
panel.getAlbums()
})
.catch(error => {
console.log(error)
panel.isLoading(element, false)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
}
panel.getAlbumsSidebar = () => {
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 occurred!', response.data.description, 'error')
}
}
const albumsContainer = document.getElementById('albumsContainer')
albumsContainer.innerHTML = ''
if (response.data.albums === undefined) { return }
for (const album of response.data.albums) {
const li = document.createElement('li')
const 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 => {
console.log(error)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
}
panel.getAlbum = album => {
panel.setActiveMenu(album)
panel.getUploads(album.id)
}
panel.changeFileLength = () => {
axios.get('api/filelength/config')
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return panel.verifyToken(panel.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
panel.page.innerHTML = `
Default file name length is ${response.data.config.default} characters. ${response.data.config.userChangeable ? `Range allowed for user is ${response.data.config.min} to ${response.data.config.max} characters.` : 'Changing file name length is disabled at the moment.'}
`
document.getElementById('setFileLength').addEventListener('click', function () {
panel.setFileLength(document.getElementById('fileLength').value, this)
})
})
.catch(error => {
console.log(error)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
}
panel.setFileLength = (fileLength, element) => {
panel.isLoading(element, true)
axios.post('api/filelength/change', { fileLength })
.then(response => {
panel.isLoading(element, false)
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return panel.verifyToken(panel.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
swal({
title: 'Woohoo!',
text: 'Your file length was successfully changed.',
icon: 'success'
}).then(() => {
location.reload()
})
})
.catch(error => {
console.log(error)
panel.isLoading(element, false)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
}
panel.changeToken = () => {
axios.get('api/tokens')
.then(response => {
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return panel.verifyToken(panel.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
panel.page.innerHTML = `