mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
feat: add max file count validation for OneDrive file selection
This commit is contained in:
parent
18e784d88b
commit
6392e33dce
2 changed files with 30 additions and 7 deletions
|
|
@ -1547,7 +1547,11 @@
|
|||
}}
|
||||
uploadOneDriveHandler={async (authorityType) => {
|
||||
try {
|
||||
const filesData = await pickAndDownloadFiles(authorityType);
|
||||
const maxFileCount = $config?.file?.max_count;
|
||||
const filesData = await pickAndDownloadFiles(
|
||||
authorityType,
|
||||
maxFileCount
|
||||
);
|
||||
if (filesData && filesData.length > 0) {
|
||||
if (filesData.length > 1) {
|
||||
toast.success(
|
||||
|
|
@ -1568,11 +1572,22 @@
|
|||
}
|
||||
} catch (error) {
|
||||
console.error('OneDrive Error:', error);
|
||||
toast.error(
|
||||
$i18n.t('OneDrive Error: {{error}}', {
|
||||
error: error.message
|
||||
})
|
||||
);
|
||||
// Handle specific max file count error
|
||||
if (error.message?.startsWith('MAX_FILE_COUNT_EXCEEDED:')) {
|
||||
const [, count, max] = error.message.split(':');
|
||||
toast.error(
|
||||
$i18n.t('Selected items contain {{count}} files, but maximum is {{max}}.', {
|
||||
count,
|
||||
max
|
||||
})
|
||||
);
|
||||
} else {
|
||||
toast.error(
|
||||
$i18n.t('OneDrive Error: {{error}}', {
|
||||
error: error.message
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}}
|
||||
{onUpload}
|
||||
|
|
|
|||
|
|
@ -501,7 +501,8 @@ export async function openOneDrivePicker(
|
|||
|
||||
// Pick and download multiple files from OneDrive (with folder support)
|
||||
export async function pickAndDownloadFiles(
|
||||
authorityType?: 'personal' | 'organizations'
|
||||
authorityType?: 'personal' | 'organizations',
|
||||
maxFileCount?: number
|
||||
): Promise<{ blob: Blob; name: string }[] | null> {
|
||||
const pickerResult = await openOneDrivePicker(authorityType);
|
||||
|
||||
|
|
@ -528,6 +529,13 @@ export async function pickAndDownloadFiles(
|
|||
throw new Error('No files found in the selected items.');
|
||||
}
|
||||
|
||||
// Check if the number of files exceeds the configured maximum
|
||||
if (maxFileCount && allFiles.length > maxFileCount) {
|
||||
throw new Error(
|
||||
`MAX_FILE_COUNT_EXCEEDED:${allFiles.length}:${maxFileCount}`
|
||||
);
|
||||
}
|
||||
|
||||
// Download all files with error handling
|
||||
const downloadPromises = allFiles.map(async (fileInfo) => {
|
||||
const blob = await downloadOneDriveFile(fileInfo, authorityType);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue