fix: re-upload with different name maintains original name (#37313)
* fix: use actual file name for private files * fix: add id to download button * fix: add fid in view file too --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
commit
6556c13ba5
2 changed files with 8 additions and 6 deletions
|
|
@ -3,7 +3,9 @@ frappe.ui.form.on("File", {
|
|||
if (frm.doc.file_url) {
|
||||
frm.add_custom_button(__("View File"), () => {
|
||||
if (!frappe.utils.is_url(frm.doc.file_url)) {
|
||||
window.open(window.location.origin + frm.doc.file_url);
|
||||
window.open(
|
||||
window.location.origin + frm.doc.file_url + "?fid=" + frm.doc.name
|
||||
);
|
||||
} else {
|
||||
window.open(frm.doc.file_url);
|
||||
}
|
||||
|
|
@ -90,7 +92,7 @@ frappe.ui.form.on("File", {
|
|||
},
|
||||
|
||||
download: function (frm) {
|
||||
let file_url = frm.doc.file_url;
|
||||
let file_url = frm.doc.file_url + "?fid=" + frm.doc.name;
|
||||
if (frm.doc.file_name) {
|
||||
file_url = file_url.replace(/#/g, "%23");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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