Skip to content

Commit 6c6ba81

Browse files
waleedlatif1claude
andcommitted
refactor(knowledge): reuse existing getMimeTypeFromExtension from uploads
Replace duplicate EXTENSION_MIME_MAP and getMimeTypeFromExtension with the existing, more comprehensive version from lib/uploads/utils/file-utils. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent daeaea6 commit 6c6ba81

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

apps/sim/tools/knowledge/types.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
1-
const EXTENSION_MIME_MAP: Record<string, string> = {
2-
html: 'text/html',
3-
htm: 'text/html',
4-
md: 'text/markdown',
5-
csv: 'text/csv',
6-
json: 'application/json',
7-
yaml: 'application/x-yaml',
8-
yml: 'application/x-yaml',
9-
xml: 'application/xml',
10-
txt: 'text/plain',
11-
} as const
12-
13-
/**
14-
* Infers MIME type from a file extension. Returns `text/plain` for unknown extensions.
15-
*/
16-
export function getMimeTypeFromExtension(ext: string): string {
17-
return EXTENSION_MIME_MAP[ext.toLowerCase()] ?? 'text/plain'
18-
}
1+
import {
2+
getFileExtension,
3+
getMimeTypeFromExtension as getUploadMimeType,
4+
} from '@/lib/uploads/utils/file-utils'
195

206
/**
217
* Extracts extension from a filename and returns the normalized filename and MIME type.
228
* If no extension is present, appends `.txt` and uses `text/plain`.
9+
* Falls back to `text/plain` for unknown extensions (knowledge docs are always text content).
2310
*/
2411
export function inferDocumentFileInfo(documentName: string): {
2512
filename: string
2613
mimeType: string
2714
} {
28-
const dotIndex = documentName.lastIndexOf('.')
29-
if (dotIndex > 0) {
30-
const ext = documentName.slice(dotIndex + 1).toLowerCase()
31-
return { filename: documentName, mimeType: getMimeTypeFromExtension(ext) }
15+
const ext = getFileExtension(documentName)
16+
if (ext) {
17+
const mimeType = getUploadMimeType(ext)
18+
return {
19+
filename: documentName,
20+
mimeType: mimeType === 'application/octet-stream' ? 'text/plain' : mimeType,
21+
}
3222
}
3323
return { filename: `${documentName}.txt`, mimeType: 'text/plain' }
3424
}

0 commit comments

Comments
 (0)