Skip to content

Commit 43cb124

Browse files
authored
fix(parsers): fix md, pptx, html kb uploads (#1209)
* fix md, pptx, html * consolidate consts
1 parent 76889fd commit 43cb124

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
lines changed

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/upload-modal/upload-modal.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,12 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/u
77
import { Label } from '@/components/ui/label'
88
import { Progress } from '@/components/ui/progress'
99
import { createLogger } from '@/lib/logs/console/logger'
10+
import { ACCEPT_ATTRIBUTE, ACCEPTED_FILE_TYPES, MAX_FILE_SIZE } from '@/lib/uploads/validation'
1011
import { getDocumentIcon } from '@/app/workspace/[workspaceId]/knowledge/components'
1112
import { useKnowledgeUpload } from '@/app/workspace/[workspaceId]/knowledge/hooks/use-knowledge-upload'
1213

1314
const logger = createLogger('UploadModal')
1415

15-
const MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB
16-
const ACCEPTED_FILE_TYPES = [
17-
'application/pdf',
18-
'application/msword',
19-
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
20-
'text/plain',
21-
'text/csv',
22-
'application/vnd.ms-excel',
23-
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
24-
'text/markdown',
25-
'application/vnd.ms-powerpoint',
26-
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
27-
'text/html',
28-
]
29-
3016
interface FileWithPreview extends File {
3117
preview: string
3218
}
@@ -172,7 +158,7 @@ export function UploadModal({
172158

173159
return (
174160
<Dialog open={open} onOpenChange={handleClose}>
175-
<DialogContent className='flex max-h-[95vh] max-w-2xl flex-col overflow-hidden'>
161+
<DialogContent className='flex max-h-[95vh] flex-col overflow-hidden sm:max-w-[600px]'>
176162
<DialogHeader>
177163
<DialogTitle>Upload Documents</DialogTitle>
178164
</DialogHeader>
@@ -197,7 +183,7 @@ export function UploadModal({
197183
<input
198184
ref={fileInputRef}
199185
type='file'
200-
accept={ACCEPTED_FILE_TYPES.join(',')}
186+
accept={ACCEPT_ATTRIBUTE}
201187
onChange={handleFileChange}
202188
className='hidden'
203189
multiple
@@ -228,7 +214,7 @@ export function UploadModal({
228214
<input
229215
ref={fileInputRef}
230216
type='file'
231-
accept={ACCEPTED_FILE_TYPES.join(',')}
217+
accept={ACCEPT_ATTRIBUTE}
232218
onChange={handleFileChange}
233219
className='hidden'
234220
multiple
@@ -238,7 +224,7 @@ export function UploadModal({
238224
</p>
239225
</div>
240226

241-
<div className='max-h-60 space-y-2 overflow-auto'>
227+
<div className='max-h-80 space-y-2 overflow-auto'>
242228
{files.map((file, index) => {
243229
const fileStatus = uploadProgress.fileStatuses?.[index]
244230
const isCurrentlyUploading = fileStatus?.status === 'uploading'

apps/sim/app/workspace/[workspaceId]/knowledge/components/create-modal/create-modal.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,13 @@ import { Label } from '@/components/ui/label'
1414
import { Progress } from '@/components/ui/progress'
1515
import { Textarea } from '@/components/ui/textarea'
1616
import { createLogger } from '@/lib/logs/console/logger'
17+
import { ACCEPT_ATTRIBUTE, ACCEPTED_FILE_TYPES, MAX_FILE_SIZE } from '@/lib/uploads/validation'
1718
import { getDocumentIcon } from '@/app/workspace/[workspaceId]/knowledge/components'
1819
import { useKnowledgeUpload } from '@/app/workspace/[workspaceId]/knowledge/hooks/use-knowledge-upload'
1920
import type { KnowledgeBaseData } from '@/stores/knowledge/store'
2021

2122
const logger = createLogger('CreateModal')
2223

23-
const MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB
24-
const ACCEPTED_FILE_TYPES = [
25-
'application/pdf',
26-
'application/msword',
27-
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
28-
'text/plain',
29-
'text/csv',
30-
'application/vnd.ms-excel',
31-
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
32-
'text/markdown',
33-
'application/vnd.ms-powerpoint',
34-
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
35-
'text/html',
36-
]
37-
3824
interface FileWithPreview extends File {
3925
preview: string
4026
}
@@ -498,7 +484,7 @@ export function CreateModal({ open, onOpenChange, onKnowledgeBaseCreated }: Crea
498484
<input
499485
ref={fileInputRef}
500486
type='file'
501-
accept={ACCEPTED_FILE_TYPES.join(',')}
487+
accept={ACCEPT_ATTRIBUTE}
502488
onChange={handleFileChange}
503489
className='hidden'
504490
multiple
@@ -540,7 +526,7 @@ export function CreateModal({ open, onOpenChange, onKnowledgeBaseCreated }: Crea
540526
<input
541527
ref={fileInputRef}
542528
type='file'
543-
accept={ACCEPTED_FILE_TYPES.join(',')}
529+
accept={ACCEPT_ATTRIBUTE}
544530
onChange={handleFileChange}
545531
className='hidden'
546532
multiple

apps/sim/lib/uploads/validation.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import path from 'path'
22

3+
export const MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB
4+
35
export const SUPPORTED_DOCUMENT_EXTENSIONS = [
46
'pdf',
57
'csv',
@@ -9,21 +11,49 @@ export const SUPPORTED_DOCUMENT_EXTENSIONS = [
911
'md',
1012
'xlsx',
1113
'xls',
14+
'ppt',
15+
'pptx',
16+
'html',
17+
'htm',
1218
] as const
1319

1420
export type SupportedDocumentExtension = (typeof SUPPORTED_DOCUMENT_EXTENSIONS)[number]
1521

1622
export const SUPPORTED_MIME_TYPES: Record<SupportedDocumentExtension, string[]> = {
17-
pdf: ['application/pdf'],
18-
csv: ['text/csv', 'application/csv'],
19-
doc: ['application/msword'],
20-
docx: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
21-
txt: ['text/plain'],
22-
md: ['text/markdown', 'text/x-markdown'],
23-
xlsx: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
24-
xls: ['application/vnd.ms-excel'],
23+
pdf: ['application/pdf', 'application/x-pdf'],
24+
csv: ['text/csv', 'application/csv', 'text/comma-separated-values'],
25+
doc: ['application/msword', 'application/doc', 'application/vnd.ms-word'],
26+
docx: [
27+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
28+
'application/octet-stream',
29+
],
30+
txt: ['text/plain', 'text/x-plain', 'application/txt'],
31+
md: ['text/markdown', 'text/x-markdown', 'text/plain', 'application/markdown'],
32+
xlsx: [
33+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
34+
'application/octet-stream',
35+
],
36+
xls: [
37+
'application/vnd.ms-excel',
38+
'application/excel',
39+
'application/x-excel',
40+
'application/x-msexcel',
41+
],
42+
ppt: ['application/vnd.ms-powerpoint', 'application/powerpoint', 'application/x-mspowerpoint'],
43+
pptx: [
44+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
45+
'application/octet-stream',
46+
],
47+
html: ['text/html', 'application/xhtml+xml'],
48+
htm: ['text/html', 'application/xhtml+xml'],
2549
}
2650

51+
export const ACCEPTED_FILE_TYPES = Object.values(SUPPORTED_MIME_TYPES).flat()
52+
53+
export const ACCEPTED_FILE_EXTENSIONS = SUPPORTED_DOCUMENT_EXTENSIONS.map((ext) => `.${ext}`)
54+
55+
export const ACCEPT_ATTRIBUTE = [...ACCEPTED_FILE_TYPES, ...ACCEPTED_FILE_EXTENSIONS].join(',')
56+
2757
export interface FileValidationError {
2858
code: 'UNSUPPORTED_FILE_TYPE' | 'MIME_TYPE_MISMATCH'
2959
message: string

0 commit comments

Comments
 (0)