Skip to content

Agent Zero AI framework

Add directory ZIP downloads to file browser

Alessandroff1f26f6acc9
diff --git a/api/download_work_dir_file.py b/api/download_work_dir_file.py
index 595d0ca6f..034156389 100644
--- a/api/download_work_dir_file.py
+++ b/api/download_work_dir_file.py
@@ -133,17 +133,19 @@ class DownloadFile(ApiHandler):
if file["is_dir"]:
zip_file = await runtime.call_development_function(files.zip_dir, file["abs_path"])
+ directory_name = os.path.basename(file_path.rstrip("/")) or "directory"
+ download_name = f"{directory_name}.zip"
if runtime.is_development():
b64 = await runtime.call_development_function(fetch_file, zip_file)
file_data = BytesIO(base64.b64decode(b64))
return stream_file_download(
file_data,
- download_name=os.path.basename(zip_file)
+ download_name=download_name
)
else:
return stream_file_download(
zip_file,
- download_name=f"{os.path.basename(file_path)}.zip"
+ download_name=download_name
)
elif file["is_file"]:
if runtime.is_development():
diff --git a/webui/components/modals/file-browser/file-browser-store.js b/webui/components/modals/file-browser/file-browser-store.js
index 4d7cd458b..6acb2706a 100644
--- a/webui/components/modals/file-browser/file-browser-store.js
+++ b/webui/components/modals/file-browser/file-browser-store.js
@@ -454,7 +454,7 @@ const model = {
downloadFile(file) {
const link = document.createElement("a");
link.href = `/api/download_work_dir_file?path=${encodeURIComponent(file.path)}`;
- link.download = file.name;
+ link.download = file.is_dir ? `${file.name}.zip` : file.name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
diff --git a/webui/components/modals/file-browser/file-browser.html b/webui/components/modals/file-browser/file-browser.html
index 6c531522e..6e5e8ac63 100644
--- a/webui/components/modals/file-browser/file-browser.html
+++ b/webui/components/modals/file-browser/file-browser.html
@@ -93,6 +93,16 @@
<span>Edit</span>
</button>
+ <button
+ type="button"
+ class="dropdown-item"
+ x-show="file.is_dir"
+ @click="$store.fileBrowser.downloadFile(file)"
+ >
+ <span class="material-symbols-outlined">folder_zip</span>
+ <span>Download ZIP</span>
+ </button>
+
<button
type="button"
class="dropdown-item"