jump back to root when run into 403

This commit is contained in:
lelo 2025-03-16 22:51:44 +01:00
parent 9913b96eb9
commit 610a108bf8

View File

@ -118,14 +118,28 @@ function attachEventListeners() {
const relUrl = this.getAttribute('data-url');
if (fileType === 'music') {
const mediaUrl = '/media/' + relUrl;
const audioPlayer = document.getElementById('globalAudio');
audioPlayer.src = mediaUrl;
audioPlayer.load();
audioPlayer.play();
document.getElementById('nowPlayingInfo').textContent = relUrl;
document.querySelector('footer').style.display = 'flex';
// Check if the media URL is forbidden
fetch(mediaUrl, { method: 'HEAD' })
.then(response => {
if (response.status === 403) {
// Redirect to the root if a 403 status is returned
window.location.href = '/';
} else {
// Otherwise, play the audio
const audioPlayer = document.getElementById('globalAudio');
audioPlayer.src = mediaUrl;
audioPlayer.load();
audioPlayer.play();
document.getElementById('nowPlayingInfo').textContent = relUrl;
document.querySelector('footer').style.display = 'flex';
}
})
.catch(error => {
console.error('Error fetching media:', error);
// Optionally handle network errors here
});
} else if (fileType === 'image') {
// Open gallery modal via gallery.js function.
// Open the gallery modal for image files
openGalleryModal(relUrl);
}
});