Compare commits

...

2 Commits

Author SHA1 Message Date
b35e4030ac try fixing download 2025-05-30 10:03:19 +00:00
17c8a41229 cleanup 2025-05-30 09:47:06 +00:00

22
app.py
View File

@ -466,18 +466,30 @@ def serve_file(subpath):
filesize = os.path.getsize(file_path) filesize = os.path.getsize(file_path)
# Figure out download flag and filename # Figure out download flag and filename
ask_download = 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=ask_download, as_attachment=as_attachment ,
download_name=filename if ask_download else None download_name=download_name
) )
if not ask_download:
if as_attachment:
response.headers['X-Content-Type-Options'] = 'nosniff'
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'