`
table.appendChild(tr)
}
}
page.editAlbum = async id => {
const album = page.albums.get(id)
if (!album) { return }
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) { return }
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return page.verifyToken(page.token)
} 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')
}
page.getAlbumsSidebar()
page.getAlbums()
}
page.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 page.verifyToken(page.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
swal('Deleted!', 'Your album has been deleted.', 'success')
page.getAlbumsSidebar()
page.getAlbums()
}
page.submitAlbum = async element => {
page.isLoading(element, true)
const response = await axios.post('api/albums', {
name: document.getElementById('albumName').value
})
.catch(error => {
console.log(error)
page.isLoading(element, false)
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
})
if (!response) { return }
page.isLoading(element, false)
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return page.verifyToken(page.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
swal('Woohoo!', 'Album was created successfully', 'success')
page.getAlbumsSidebar()
page.getAlbums()
}
page.getAlbumsSidebar = async () => {
const response = await axios.get('api/albums/sidebar')
.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) { return }
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return page.verifyToken(page.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 () {
page.getAlbum(this)
})
li.appendChild(a)
albumsContainer.appendChild(li)
}
}
page.getAlbum = album => {
page.setActiveMenu(album)
page.getUploads(album.id)
}
page.changeFileLength = async () => {
const response = await axios.get('api/filelength/config')
.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) { return }
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
return page.verifyToken(page.token)
} else {
return swal('An error occurred!', response.data.description, 'error')
}
}
page.dom.innerHTML = `
File name length
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.'}