try fixing download

This commit is contained in:
lelo 2025-05-30 10:03:19 +00:00
parent 17c8a41229
commit b35e4030ac

16
app.py
View File

@ -469,14 +469,26 @@ def serve_file(subpath):
as_attachment = request.args.get('download') == 'true' as_attachment = request.args.get('download') == 'true'
filename = os.path.basename(full_path) filename = os.path.basename(full_path)
if as_attachment:
download_name = filename
mimetype = 'application/octet-stream'
else:
download_name = None
mimetype = mime
# Single send_file call with proper attachment handling # Single send_file call with proper attachment handling
response = send_file( response = send_file(
file_path, file_path,
mimetype=mime, mimetype=mimetype,
conditional=True, conditional=True,
as_attachment=as_attachment , as_attachment=as_attachment ,
download_name=filename if as_attachment else None download_name=download_name
) )
if as_attachment:
response.headers['X-Content-Type-Options'] = 'nosniff'
if not as_attachment : if not as_attachment :
response.headers['Content-Disposition'] = 'inline' response.headers['Content-Disposition'] = 'inline'
response.headers['Cache-Control'] = 'public, max-age=86400' response.headers['Cache-Control'] = 'public, max-age=86400'