fix(response): set content-disposition header correctly again
Broke in ee2c4c20ce
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
0390c8d933
commit
c14e9d5d20
1 changed files with 9 additions and 4 deletions
|
|
@ -298,10 +298,16 @@ def download_private_file(path: str) -> Response:
|
||||||
return send_private_file(path.split("/private", 1)[1])
|
return send_private_file(path.split("/private", 1)[1])
|
||||||
|
|
||||||
|
|
||||||
|
FORCE_DOWNLOAD_EXTENSIONS = (".svg", ".html", ".htm", ".xml")
|
||||||
|
|
||||||
|
|
||||||
def send_private_file(path: str) -> Response:
|
def send_private_file(path: str) -> Response:
|
||||||
path = os.path.join(frappe.local.conf.get("private_path", "private"), path.strip("/"))
|
path = os.path.join(frappe.local.conf.get("private_path", "private"), path.strip("/"))
|
||||||
filename = os.path.basename(path)
|
filename = os.path.basename(path)
|
||||||
|
|
||||||
|
extension = os.path.splitext(path)[1]
|
||||||
|
as_attachment = extension.lower() in FORCE_DOWNLOAD_EXTENSIONS
|
||||||
|
|
||||||
if frappe.local.request.headers.get("X-Use-X-Accel-Redirect"):
|
if frappe.local.request.headers.get("X-Use-X-Accel-Redirect"):
|
||||||
path = "/protected/" + path
|
path = "/protected/" + path
|
||||||
response = Response()
|
response = Response()
|
||||||
|
|
@ -310,15 +316,14 @@ def send_private_file(path: str) -> Response:
|
||||||
response.headers["Accept-Ranges"] = "bytes"
|
response.headers["Accept-Ranges"] = "bytes"
|
||||||
response.headers["Content-Type"] = mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
response.headers["Content-Type"] = mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
||||||
|
|
||||||
|
if as_attachment:
|
||||||
|
response.headers["Content-Disposition"] = f"attachment; filename*=UTF-8''{quote(filename)}"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
filepath = frappe.utils.get_site_path(path)
|
filepath = frappe.utils.get_site_path(path)
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
raise NotFound
|
raise NotFound
|
||||||
|
|
||||||
extension = os.path.splitext(path)[1]
|
|
||||||
blacklist = [".svg", ".html", ".htm", ".xml"]
|
|
||||||
as_attachment = extension.lower() in blacklist
|
|
||||||
|
|
||||||
response = werkzeug.utils.send_file(
|
response = werkzeug.utils.send_file(
|
||||||
filepath,
|
filepath,
|
||||||
environ=frappe.local.request.environ,
|
environ=frappe.local.request.environ,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue