feat(files): add folder download as zip

- Add zip folder API endpoint
- Add download button to folder rows
- Enforce max archive size limit
- Document endpoint in OpenAPI
This commit is contained in:
2026-09-01 20:20:15 +03:00
parent 1bba2c6b51
commit e7982c5487
7 changed files with 288 additions and 9 deletions
+33 -9
View File
@@ -162,6 +162,15 @@
return res.json();
}
function downloadFolder(fullPath, folderName) {
const link = document.createElement("a");
link.href = `/api/v1/files/zip?path=${encodeURIComponent(fullPath)}`;
link.download = `${folderName}.zip`;
document.body.append(link);
link.click();
link.remove();
}
async function deleteFile(fullPath, name) {
if (!confirm(`Delete ${name}?`)) {
return;
@@ -184,21 +193,37 @@
for (const entry of entries) {
const tr = document.createElement("tr");
const name = document.createElement("td");
name.className = entry.type === "dir" ? "name" : "name file";
name.textContent = entry.name;
name.addEventListener("click", () => {
const full = joinPath(data.path, entry.name);
if (entry.type === "dir") {
const full = joinPath(data.path, entry.name);
if (entry.type === "dir") {
name.className = "name dir";
const label = document.createElement("span");
label.className = "dir-label";
label.textContent = entry.name;
label.addEventListener("click", () => {
listFiles(full).catch((err) => showError(err.message));
} else {
});
const zipBtn = document.createElement("button");
zipBtn.type = "button";
zipBtn.className = "folder-zip";
zipBtn.textContent = "Download";
zipBtn.title = "Download folder as zip";
zipBtn.addEventListener("click", (event) => {
event.stopPropagation();
downloadFolder(full, entry.name);
});
name.append(label, zipBtn);
} else {
name.className = "name file";
name.textContent = entry.name;
name.addEventListener("click", () => {
const link = document.createElement("a");
link.href = `/api/v1/download?path=${encodeURIComponent(full)}`;
link.download = entry.name;
document.body.append(link);
link.click();
link.remove();
}
});
});
}
const type = document.createElement("td");
type.textContent = entry.type;
const size = document.createElement("td");
@@ -207,7 +232,6 @@
modified.textContent = entry.modified_time ? new Date(entry.modified_time).toLocaleString() : "";
const action = document.createElement("td");
action.className = "actions";
const full = joinPath(data.path, entry.name);
const del = document.createElement("button");
del.type = "button";
del.className = "danger";