Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
feat(KnowledgeBase): support up to 5 files upload of 100mb each per req
Jake Turnera14dd688fa1a
diff --git a/admin/config/bodyparser.ts b/admin/config/bodyparser.tsindex f3d1ead9..c995755f 100644--- a/admin/config/bodyparser.ts+++ b/admin/config/bodyparser.ts@@ -47,7 +47,7 @@ const bodyParserConfig = defineConfig({* Maximum limit of data to parse including all files* and fields*/- limit: '20mb',+ limit: '110mb', // Set to 110MB to allow for some overhead beyond the 100MB file size limittypes: ['multipart/form-data'],},})diff --git a/admin/inertia/components/chat/KnowledgeBaseModal.tsx b/admin/inertia/components/chat/KnowledgeBaseModal.tsxindex 00425d9b..e77a0c93 100644--- a/admin/inertia/components/chat/KnowledgeBaseModal.tsx+++ b/admin/inertia/components/chat/KnowledgeBaseModal.tsx@@ -24,6 +24,7 @@ function sourceToDisplayName(source: string): string {export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", onClose }: KnowledgeBaseModalProps) {const { addNotification } = useNotifications()const [files, setFiles] = useState<File[]>([])+ const [isUploading, setIsUploading] = useState(false)const [confirmDeleteSource, setConfirmDeleteSource] = useState<string | null>(null)const fileUploaderRef = useRef<React.ComponentRef<typeof FileUploader>>(null)const { openModal, closeModal } = useModals()@@ -37,23 +38,6 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", oconst uploadMutation = useMutation({mutationFn: (file: File) => api.uploadDocument(file),- onSuccess: (data) => {- addNotification({- type: 'success',- message: data?.message || 'Document uploaded and queued for processing',- })- setFiles([])- if (fileUploaderRef.current) {- fileUploaderRef.current.clear()- }- queryClient.invalidateQueries({ queryKey: ['embed-jobs'] })- },- onError: (error: any) => {- addNotification({- type: 'error',- message: error?.message || 'Failed to upload document',- })- },})const deleteMutation = useMutation({@@ -96,9 +80,34 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o},})- const handleUpload = () => {- if (files.length > 0) {- uploadMutation.mutate(files[0])+ const handleUpload = async () => {+ if (files.length === 0) return+ setIsUploading(true)+ let successCount = 0+ const failedNames: string[] = []++ for (const file of files) {+ try {+ await uploadMutation.mutateAsync(file)+ successCount+++ } catch (error: any) {+ failedNames.push(file.name)+ }+ }++ setIsUploading(false)+ setFiles([])+ fileUploaderRef.current?.clear()+ queryClient.invalidateQueries({ queryKey: ['embed-jobs'] })++ if (successCount > 0) {+ addNotification({+ type: 'success',+ message: `${successCount} file${successCount > 1 ? 's' : ''} queued for processing.`,+ })+ }+ for (const name of failedNames) {+ addNotification({ type: 'error', message: `Failed to upload: ${name}` })}}@@ -145,7 +154,7 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o<FileUploaderref={fileUploaderRef}minFiles={1}- maxFiles={1}+ maxFiles={5}onUpload={(uploadedFiles) => {setFiles(Array.from(uploadedFiles))}}@@ -156,8 +165,8 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", osize="lg"icon="IconUpload"onClick={handleUpload}- disabled={files.length === 0 || uploadMutation.isPending}- loading={uploadMutation.isPending}+ disabled={files.length === 0 || isUploading}+ loading={isUploading}>Upload</StyledButton>@@ -243,8 +252,8 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", osize="md"icon='IconRefresh'onClick={handleConfirmSync}- disabled={syncMutation.isPending || uploadMutation.isPending}- loading={syncMutation.isPending || uploadMutation.isPending}+ disabled={syncMutation.isPending || isUploading}+ loading={syncMutation.isPending || isUploading}>Sync Storage</StyledButton>diff --git a/admin/inertia/components/file-uploader/index.tsx b/admin/inertia/components/file-uploader/index.tsxindex 0dac08ae..7d37d4fc 100644--- a/admin/inertia/components/file-uploader/index.tsx+++ b/admin/inertia/components/file-uploader/index.tsx@@ -29,7 +29,7 @@ const FileUploader = forwardRef<FileUploaderRef, FileUploaderProps>((props, ref)const {minFiles = 0,maxFiles = 1,- maxFileSize = 10485760, // default to 10MB+ maxFileSize = 104857600, // default to 100MBfileTypes,disabled = false,onUpload,