fix download delays
This commit is contained in:
parent
f2e5e2f314
commit
770ff38b64
@ -89,6 +89,7 @@ def return_file_access():
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@require_secret
|
||||||
def network():
|
def network():
|
||||||
return render_template('network.html')
|
return render_template('network.html')
|
||||||
|
|
||||||
|
|||||||
7
app.py
7
app.py
@ -140,10 +140,12 @@ def generate_breadcrumbs(subpath=None):
|
|||||||
@app.route('/static/icons/<string:size>.png')
|
@app.route('/static/icons/<string:size>.png')
|
||||||
def serve_resized_icon(size):
|
def serve_resized_icon(size):
|
||||||
cached_image_bytes = get_cached_image(size)
|
cached_image_bytes = get_cached_image(size)
|
||||||
return send_file(
|
response = send_file(
|
||||||
io.BytesIO(cached_image_bytes),
|
io.BytesIO(cached_image_bytes),
|
||||||
mimetype='image/png'
|
mimetype='image/png'
|
||||||
)
|
)
|
||||||
|
response.headers['Cache-Control'] = 'public, max-age=86400'
|
||||||
|
return response
|
||||||
|
|
||||||
@app.route('/sw.js')
|
@app.route('/sw.js')
|
||||||
def serve_sw():
|
def serve_sw():
|
||||||
@ -202,8 +204,9 @@ def serve_file(subpath):
|
|||||||
# HEAD request are coming in to initiate server caching.
|
# HEAD request are coming in to initiate server caching.
|
||||||
# only log initial hits and not the reload of further file parts
|
# only log initial hits and not the reload of further file parts
|
||||||
range_header = request.headers.get('Range')
|
range_header = request.headers.get('Range')
|
||||||
|
# only request with starting from the beginning of the file will be tracked
|
||||||
if request.method != 'HEAD' and (not range_header or range_header.startswith("bytes=0-")):
|
if request.method != 'HEAD' and (not range_header or range_header.startswith("bytes=0-")):
|
||||||
a.log_file_access(full_path)
|
threading.Thread(target=a.log_file_access, args=(full_path,)).start()
|
||||||
|
|
||||||
# Check cache first (using diskcache)
|
# Check cache first (using diskcache)
|
||||||
response = None
|
response = None
|
||||||
|
|||||||
@ -238,19 +238,20 @@ document.querySelectorAll('.play-file').forEach(link => {
|
|||||||
const folderName = pathParts[pathParts.length - 2];
|
const folderName = pathParts[pathParts.length - 2];
|
||||||
const fileName = pathParts.pop();
|
const fileName = pathParts.pop();
|
||||||
const pathStr = pathParts.join('/');
|
const pathStr = pathParts.join('/');
|
||||||
nowPlayingInfo.innerHTML = pathStr.replace(/\//g, ' > ') + '<br><span style="font-size: larger; font-weight: bold;">' + fileName.replace('.mp3', '') + '</span>';
|
|
||||||
// write into hardware player
|
// write into hardware player
|
||||||
if ('mediaSession' in navigator) {
|
if ('mediaSession' in navigator) {
|
||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
title: currentMusicFiles[currentMusicIndex].title,
|
title: currentMusicFiles[currentMusicIndex].title,
|
||||||
artist: folderName,
|
artist: folderName,
|
||||||
artwork: [
|
artwork: [
|
||||||
{ src: '/static/icons/logo-512x512.png', sizes: '512x512', type: 'image/png' }
|
{ src: '/static/icons/logo-192x192.png', sizes: '192x192', type: 'image/png' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
preload_audio();
|
nowPlayingInfo.innerHTML = pathStr.replace(/\//g, ' > ') + '<br><span style="font-size: larger; font-weight: bold;">' + fileName.replace('.mp3', '') + '</span>';
|
||||||
}
|
// Delay preloading to avoid blocking playback
|
||||||
|
setTimeout(preload_audio, 1000);
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If the fetch was aborted, error.name will be 'AbortError'.
|
// If the fetch was aborted, error.name will be 'AbortError'.
|
||||||
if (error.name === 'AbortError') {
|
if (error.name === 'AbortError') {
|
||||||
@ -258,12 +259,12 @@ document.querySelectorAll('.play-file').forEach(link => {
|
|||||||
} else {
|
} else {
|
||||||
console.error('Error fetching media:', error);
|
console.error('Error fetching media:', error);
|
||||||
nowPlayingInfo.textContent = "Fehler: Netzwerkproblem oder ungültige URL.";
|
nowPlayingInfo.textContent = "Fehler: Netzwerkproblem oder ungültige URL.";
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
} else if (fileType === 'image') {
|
} else if (fileType === 'image') {
|
||||||
// Open the gallery modal for image files.
|
// Open the gallery modal for image files.
|
||||||
openGalleryModal(relUrl);
|
openGalleryModal(relUrl);
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<!-- Bootstrap 5 JS Bundle -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user