jump back to root when run into 403
This commit is contained in:
parent
9913b96eb9
commit
610a108bf8
@ -118,14 +118,28 @@ function attachEventListeners() {
|
|||||||
const relUrl = this.getAttribute('data-url');
|
const relUrl = this.getAttribute('data-url');
|
||||||
if (fileType === 'music') {
|
if (fileType === 'music') {
|
||||||
const mediaUrl = '/media/' + relUrl;
|
const mediaUrl = '/media/' + relUrl;
|
||||||
const audioPlayer = document.getElementById('globalAudio');
|
// Check if the media URL is forbidden
|
||||||
audioPlayer.src = mediaUrl;
|
fetch(mediaUrl, { method: 'HEAD' })
|
||||||
audioPlayer.load();
|
.then(response => {
|
||||||
audioPlayer.play();
|
if (response.status === 403) {
|
||||||
document.getElementById('nowPlayingInfo').textContent = relUrl;
|
// Redirect to the root if a 403 status is returned
|
||||||
document.querySelector('footer').style.display = 'flex';
|
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') {
|
} else if (fileType === 'image') {
|
||||||
// Open gallery modal via gallery.js function.
|
// Open the gallery modal for image files
|
||||||
openGalleryModal(relUrl);
|
openGalleryModal(relUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user