Skip to content
Prev Previous commit
Next Next commit
refactor(knowledge): reuse existing getMimeTypeFromExtension from upl…
…oads

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>
  • Loading branch information
waleedlatif1 and claude committed Mar 18, 2026
commit 6c6ba817ef02f106078fec16b36663876193fa4d
34 changes: 12 additions & 22 deletions apps/sim/tools/knowledge/types.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
const EXTENSION_MIME_MAP: Record<string, string> = {
html: 'text/html',
htm: 'text/html',
md: 'text/markdown',
csv: 'text/csv',
json: 'application/json',
yaml: 'application/x-yaml',
yml: 'application/x-yaml',
xml: 'application/xml',
txt: 'text/plain',
} as const

/**
* Infers MIME type from a file extension. Returns `text/plain` for unknown extensions.
*/
export function getMimeTypeFromExtension(ext: string): string {
return EXTENSION_MIME_MAP[ext.toLowerCase()] ?? 'text/plain'
}
import {
getFileExtension,
getMimeTypeFromExtension as getUploadMimeType,
} from '@/lib/uploads/utils/file-utils'

/**
* Extracts extension from a filename and returns the normalized filename and MIME type.
* If no extension is present, appends `.txt` and uses `text/plain`.
* Falls back to `text/plain` for unknown extensions (knowledge docs are always text content).
*/
export function inferDocumentFileInfo(documentName: string): {
Comment thread
waleedlatif1 marked this conversation as resolved.
filename: string
mimeType: string
} {
const dotIndex = documentName.lastIndexOf('.')
if (dotIndex > 0) {
const ext = documentName.slice(dotIndex + 1).toLowerCase()
return { filename: documentName, mimeType: getMimeTypeFromExtension(ext) }
const ext = getFileExtension(documentName)
if (ext) {
const mimeType = getUploadMimeType(ext)
return {
filename: documentName,
mimeType: mimeType === 'application/octet-stream' ? 'text/plain' : mimeType,
}
Comment thread
waleedlatif1 marked this conversation as resolved.
}
return { filename: `${documentName}.txt`, mimeType: 'text/plain' }
}
Expand Down
Loading