attempt to fix download issues

This commit is contained in:
lelo 2025-04-19 07:29:26 +00:00
parent cffb4ec9e2
commit 36af2023de
2 changed files with 19 additions and 15 deletions

View File

@ -101,30 +101,34 @@ audio.onended = function() {
async function downloadAudio() {
const src = audio.currentSrc;
const src = audio.currentSrc || audio.src;
if (!src) return;
// Fetch with credentials / correct mode
const response = await fetch(src, { credentials: 'same-origin' });
if (!response.ok) throw new Error(`Download failed: ${response.status}`);
// Build a fresh URL every time
const requestUrl = new URL(src, window.location.href);
requestUrl.searchParams.set('_', Date.now());
// Grab the data as a Blob
// Force network fetch and include sameorigin credentials
const response = await fetch(requestUrl.toString(), {
credentials: 'same-origin',
cache: 'no-store'
});
if (!response.ok) {
throw new Error(`Download failed: ${response.status}`);
}
// Turn the response into a blob, then download it
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
// Create your own blob: URL and anchor
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.href = blobUrl;
// Retain original filename if possible
let filename = decodeURIComponent(src.split('/').pop() || 'audio');
a.download = filename;
a.download = decodeURIComponent(src.split('/').pop() || 'audio');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// Cleanup
URL.revokeObjectURL(url);
URL.revokeObjectURL(blobUrl);
}

View File

@ -1,4 +1,4 @@
const cacheName = 'gottesdienste-v1.3';
const cacheName = 'gottesdienste-v1.7';
const assets = [
'/',
'/static/app.css',