refactor: simplify send_file parameters
This commit is contained in:
parent
de3c5c7800
commit
ec0a864d35
1 changed files with 7 additions and 9 deletions
|
|
@ -312,19 +312,17 @@ def send_private_file(path: str) -> Response:
|
|||
if not os.path.exists(filepath):
|
||||
raise NotFound
|
||||
|
||||
mimetype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
||||
|
||||
extension = os.path.splitext(path)[1]
|
||||
blacklist = [".svg", ".html", ".htm", ".xml"]
|
||||
as_attachment = extension.lower() in blacklist
|
||||
|
||||
send_kwargs = dict(mimetype=mimetype, conditional=True, as_attachment=as_attachment)
|
||||
environ = frappe.local.request.environ
|
||||
|
||||
if as_attachment:
|
||||
response = werkzeug.utils.send_file(filepath, environ, download_name=filename, **send_kwargs)
|
||||
else:
|
||||
response = werkzeug.utils.send_file(filepath, environ, **send_kwargs)
|
||||
response = werkzeug.utils.send_file(
|
||||
filepath,
|
||||
environ=frappe.local.request.environ,
|
||||
conditional=True,
|
||||
as_attachment=as_attachment,
|
||||
download_name=filename if as_attachment else None,
|
||||
)
|
||||
|
||||
return response
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue