fix: use actual file name for private files
This commit is contained in:
parent
69dbd05e87
commit
cdb50bde65
1 changed files with 4 additions and 4 deletions
|
|
@ -295,15 +295,15 @@ def download_private_file(path: str) -> Response:
|
|||
raise Forbidden(_("You don't have permission to access this file"))
|
||||
|
||||
make_access_log(doctype="File", document=file.name, file_type=os.path.splitext(path)[-1][1:])
|
||||
return send_private_file(path.split("/private", 1)[1])
|
||||
return send_private_file(path.split("/private", 1)[1], filename=file.file_name)
|
||||
|
||||
|
||||
FORCE_DOWNLOAD_EXTENSIONS = (".svg", ".html", ".htm", ".xml")
|
||||
|
||||
|
||||
def send_private_file(path: str) -> Response:
|
||||
def send_private_file(path: str, filename: str | None = None) -> Response:
|
||||
path = os.path.join(frappe.local.conf.get("private_path", "private"), path.strip("/"))
|
||||
filename = os.path.basename(path)
|
||||
filename = filename or os.path.basename(path)
|
||||
|
||||
extension = os.path.splitext(path)[1]
|
||||
as_attachment = extension.lower() in FORCE_DOWNLOAD_EXTENSIONS
|
||||
|
|
@ -329,7 +329,7 @@ def send_private_file(path: str) -> Response:
|
|||
environ=frappe.local.request.environ,
|
||||
conditional=True,
|
||||
as_attachment=as_attachment,
|
||||
download_name=filename if as_attachment else None,
|
||||
download_name=filename,
|
||||
)
|
||||
|
||||
return response
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue