From a71df1839f9ef80e5a1a162007c972f32deb7e8e Mon Sep 17 00:00:00 2001 From: gavin Date: Mon, 27 May 2024 16:00:48 +0200 Subject: [PATCH] fix: Drop file_manager.download_file (#26575) Closes https://github.com/frappe/frappe/issues/26424 --- frappe/hooks.py | 1 + frappe/utils/file_manager.py | 21 --------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/frappe/hooks.py b/frappe/hooks.py index fdc0afa1ac..c603156b0a 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -371,6 +371,7 @@ global_search_doctypes = { override_whitelisted_methods = { # Legacy File APIs + "frappe.utils.file_manager.download_file": "download_file", "frappe.core.doctype.file.file.download_file": "download_file", "frappe.core.doctype.file.file.unzip_file": "frappe.core.api.file.unzip_file", "frappe.core.doctype.file.file.get_attached_images": "frappe.core.api.file.get_attached_images", diff --git a/frappe/utils/file_manager.py b/frappe/utils/file_manager.py index 9aafeb6dfa..ac6a705353 100644 --- a/frappe/utils/file_manager.py +++ b/frappe/utils/file_manager.py @@ -395,27 +395,6 @@ def get_file_name(fname, optional_suffix): return fname -@frappe.whitelist() -def download_file(file_url): - """ - Download file using token and REST API. Valid session or - token is required to download private files. - - Method : GET - Endpoint : frappe.utils.file_manager.download_file - URL Params : file_name = /path/to/file relative to site path - """ - file_doc = frappe.get_doc("File", {"file_url": file_url}) - file_doc.check_permission("read") - path = os.path.join(get_files_path(), os.path.basename(file_url)) - - with open(path, "rb") as fileobj: - filedata = fileobj.read() - frappe.local.response.filename = os.path.basename(file_url) - frappe.local.response.filecontent = filedata - frappe.local.response.type = "download" - - @frappe.whitelist() def add_attachments(doctype, name, attachments): """Add attachments to the given DocType"""