mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-13 12:55:19 +00:00
Support folder drag-n-drop (#19320)
This commit is contained in:
parent
ff7a54653a
commit
22e85df448
1 changed files with 31 additions and 5 deletions
|
|
@ -546,14 +546,40 @@
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dragged = false;
|
dragged = false;
|
||||||
|
|
||||||
|
const handleUploadingFileFolder = (items) => {
|
||||||
|
for(const item of items) {
|
||||||
|
|
||||||
|
if(item.isFile) {
|
||||||
|
item.file((file) => {
|
||||||
|
uploadFileHandler(file);
|
||||||
|
})
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not sure why you have to call webkitGetAsEntry and isDirectory seperate, but it won't work if you try item.webkitGetAsEntry().isDirectory
|
||||||
|
const wkentry = item.webkitGetAsEntry();
|
||||||
|
const isDirectory = wkentry.isDirectory;
|
||||||
|
if(isDirectory) {
|
||||||
|
// Read the directory
|
||||||
|
wkentry.createReader().readEntries((entries) => {
|
||||||
|
handleUploadingFileFolder(entries)
|
||||||
|
}, (error) => {
|
||||||
|
console.error('Error reading directory entries:', error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast.info($i18n.t('Uploading file...'));
|
||||||
|
uploadFileHandler(item.getAsFile());
|
||||||
|
toast.success($i18n.t('File uploaded!'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (e.dataTransfer?.types?.includes('Files')) {
|
if (e.dataTransfer?.types?.includes('Files')) {
|
||||||
if (e.dataTransfer?.files) {
|
if (e.dataTransfer?.files) {
|
||||||
const inputFiles = e.dataTransfer?.files;
|
const inputItems = e.dataTransfer?.items;
|
||||||
|
|
||||||
if (inputFiles && inputFiles.length > 0) {
|
if (inputItems && inputItems.length > 0) {
|
||||||
for (const file of inputFiles) {
|
handleUploadingFileFolder(inputItems)
|
||||||
await uploadFileHandler(file);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
toast.error($i18n.t(`File not found.`));
|
toast.error($i18n.t(`File not found.`));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue