Add more file formats

This commit is contained in:
Joey Yakimowich-Payne 2026-01-19 15:00:25 -07:00
commit b80254418b
No known key found for this signature in database
GPG key ID: DDF6AF5B21B407D4
5 changed files with 297 additions and 6 deletions

View file

@ -7,6 +7,19 @@ export const GEMINI_NATIVE_TYPES = [
'text/markdown',
'text/csv',
'text/html',
'text/xml',
'application/xml',
'application/json',
'text/javascript',
'application/javascript',
'text/x-python',
'text/x-java-source',
'text/x-c',
'text/x-c++',
'text/x-typescript',
'text/css',
'text/yaml',
'application/x-yaml',
'image/jpeg',
'image/png',
'image/gif',
@ -34,6 +47,51 @@ export const OCR_CAPABLE_TYPES = [
export const SUPPORTED_TYPES = [...GEMINI_NATIVE_TYPES, ...OFFICEPARSER_TYPES];
const EXTENSION_TO_MIME: Record<string, string> = {
'.txt': 'text/plain',
'.md': 'text/markdown',
'.markdown': 'text/markdown',
'.csv': 'text/csv',
'.html': 'text/html',
'.htm': 'text/html',
'.xml': 'application/xml',
'.json': 'application/json',
'.js': 'text/javascript',
'.mjs': 'text/javascript',
'.ts': 'text/x-typescript',
'.tsx': 'text/x-typescript',
'.jsx': 'text/javascript',
'.py': 'text/x-python',
'.java': 'text/x-java-source',
'.c': 'text/x-c',
'.h': 'text/x-c',
'.cpp': 'text/x-c++',
'.hpp': 'text/x-c++',
'.cc': 'text/x-c++',
'.css': 'text/css',
'.yaml': 'text/yaml',
'.yml': 'text/yaml',
};
export function normalizeMimeType(mimeType: string, filename?: string): string {
if (SUPPORTED_TYPES.includes(mimeType)) {
return mimeType;
}
if (mimeType === 'application/octet-stream' && filename) {
const ext = filename.toLowerCase().match(/\.[^.]+$/)?.[0];
if (ext && EXTENSION_TO_MIME[ext]) {
return EXTENSION_TO_MIME[ext];
}
}
if (mimeType.startsWith('text/') && !SUPPORTED_TYPES.includes(mimeType)) {
return 'text/plain';
}
return mimeType;
}
export interface ProcessedDocument {
type: 'native' | 'text';
content: Buffer | string;