From 35b65bc7924ef718fd8fc996c085e03d71eb573e Mon Sep 17 00:00:00 2001 From: Safwan Samsudeen Date: Tue, 12 Aug 2025 13:58:25 +0530 Subject: [PATCH 01/10] feat: allow adding other methods of file upload --- frappe/public/js/frappe/file_uploader/FileUploader.vue | 9 +++++++++ .../js/frappe/file_uploader/file_uploader.bundle.js | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/frappe/public/js/frappe/file_uploader/FileUploader.vue b/frappe/public/js/frappe/file_uploader/FileUploader.vue index b94b964876..cb04670bcd 100644 --- a/frappe/public/js/frappe/file_uploader/FileUploader.vue +++ b/frappe/public/js/frappe/file_uploader/FileUploader.vue @@ -163,6 +163,12 @@
{{ __("Google Drive") }}
+
{{ upload_notes }} @@ -291,6 +297,9 @@ const props = defineProps({ allow_google_drive: { default: true, }, + other_options: { + default: () => [], + }, }); // variables diff --git a/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js b/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js index c9734f7d6c..56b866d8a4 100644 --- a/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js +++ b/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js @@ -65,6 +65,7 @@ class FileUploader { allow_toggle_private, allow_toggle_optimize, allow_google_drive, + other_options: this.get_extra_options(), }); SetVueGlobals(app); this.uploader = app.mount(this.wrapper); @@ -126,6 +127,11 @@ class FileUploader { return this.uploader.upload_files(this.dialog); } + get_extra_options() { + // Defaults to empty list, can be overriden externally + return []; + } + make_dialog(title) { this.dialog = new frappe.ui.Dialog({ title: title || __("Upload"), From adc477f2553c1d87b670cad0b89070b4ecb427e5 Mon Sep 17 00:00:00 2001 From: Safwan Samsudeen Date: Fri, 22 Aug 2025 14:54:24 +0530 Subject: [PATCH 02/10] feat: tweak to allow drive links --- frappe/core/doctype/file/file.py | 9 ++++++--- .../js/frappe/file_uploader/FileUploader.vue | 2 +- .../frappe/file_uploader/file_uploader.bundle.js | 16 +++++++++++++++- frappe/utils/file_manager.py | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 5cbef2db16..c82636efd4 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -31,7 +31,7 @@ from .utils import * exclude_from_linked_with = True ImageFile.LOAD_TRUNCATED_IMAGES = True -URL_PREFIXES = ("http://", "https://") +URL_PREFIXES = ("http://", "https://", "/api/method/drive.api.files.get_file_content") FILE_ENCODING_OPTIONS = ("utf-8-sig", "utf-8", "windows-1250", "windows-1252") @@ -213,8 +213,8 @@ class File(Document): if self.is_remote_file or not self.file_url: return - if not self.file_url.startswith(("/files/", "/private/files/")): - # Probably an invalid URL since it doesn't start with http either + if not self.file_url.startswith(("/files/", "/private/files/", "/api/method/drive.api.files.get_file_content")): + # Probably an invalid URL since it doesn't start with http and isn't a Drive URL either frappe.throw( _("URL must start with http:// or https://"), title=_("Invalid URL"), @@ -779,6 +779,9 @@ class File(Document): frappe.clear_messages() def set_is_private(self): + if self.is_private: + return + if self.file_url: self.is_private = cint(self.file_url.startswith("/private")) diff --git a/frappe/public/js/frappe/file_uploader/FileUploader.vue b/frappe/public/js/frappe/file_uploader/FileUploader.vue index cb04670bcd..6807bb1647 100644 --- a/frappe/public/js/frappe/file_uploader/FileUploader.vue +++ b/frappe/public/js/frappe/file_uploader/FileUploader.vue @@ -164,7 +164,7 @@
{{ __("Google Drive") }}