diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 8c6b958985..48994873fb 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -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} diff --git a/src/lib/utils/onedrive-file-picker.ts b/src/lib/utils/onedrive-file-picker.ts index 1f183744f4..55c3b92374 100644 --- a/src/lib/utils/onedrive-file-picker.ts +++ b/src/lib/utils/onedrive-file-picker.ts @@ -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);