feat(web): add file sorting to files browser
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
+17
-11
@@ -9,6 +9,7 @@
|
||||
const filesInput = document.getElementById("upload-files-input");
|
||||
const folderInput = document.getElementById("upload-folder-input");
|
||||
const newFolderButton = document.getElementById("new-folder-button");
|
||||
const sortSelect = document.getElementById("sort-select");
|
||||
const status = document.getElementById("upload-status");
|
||||
if (!dropZone) {
|
||||
return;
|
||||
@@ -25,11 +26,6 @@
|
||||
}
|
||||
const formData = new FormData();
|
||||
for (const file of files) {
|
||||
// A folder-selected/dropped file's relative path (e.g.
|
||||
// "photos/2024/img.jpg") is sent as a parallel "paths" field
|
||||
// (same order as "files") since the server strips any
|
||||
// directory component from the file's own filename per the
|
||||
// multipart spec — see internal/web/files.go.
|
||||
const relPath = file.webkitRelativePath || file.name;
|
||||
formData.append("files", file, file.name);
|
||||
formData.append("paths", relPath);
|
||||
@@ -106,10 +102,22 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
// Recursively walk a dropped DataTransferItem (file or directory) into
|
||||
// a flat list of File objects, using the browser's non-standard but
|
||||
// widely-supported webkitGetAsEntry/FileSystemEntry APIs to support
|
||||
// dragging & dropping whole folders.
|
||||
if (sortSelect) {
|
||||
sortSelect.addEventListener("change", () => {
|
||||
const value = sortSelect.value;
|
||||
let sortBy = "name";
|
||||
let sortDir = "asc";
|
||||
if (value === "name_asc") {
|
||||
sortBy = "name";
|
||||
sortDir = "asc";
|
||||
}
|
||||
else if (value === "name_desc") {
|
||||
sortBy = "name";
|
||||
sortDir = "desc";
|
||||
}
|
||||
window.location.href = `${uploadUrl}?sort_by=${sortBy}&sort_dir=${sortDir}`;
|
||||
});
|
||||
}
|
||||
function readEntry(entry) {
|
||||
return new Promise((resolve) => {
|
||||
if (entry.isFile) {
|
||||
@@ -163,8 +171,6 @@
|
||||
}
|
||||
}
|
||||
if (entries.length === 0) {
|
||||
// Fallback for browsers without webkitGetAsEntry support: flat
|
||||
// files only, no folder traversal.
|
||||
void upload(Array.from(e.dataTransfer?.files || []));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user