Special case mime type for ts file. (#2902)

This commit is contained in:
Tommaso Sciortino
2025-07-01 16:05:33 -07:00
committed by GitHub
parent 383306e17e
commit 82afc75350
2 changed files with 12 additions and 1 deletions

View File

@@ -100,8 +100,14 @@ export function detectFileType(
filePath: string,
): 'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' {
const ext = path.extname(filePath).toLowerCase();
const lookedUpMimeType = mime.lookup(filePath); // Returns false if not found, or the mime type string
// The mimetype for "ts" is MPEG transport stream (a video format) but we want
// to assume these are typescript files instead.
if (ext === '.ts') {
return 'text';
}
const lookedUpMimeType = mime.lookup(filePath); // Returns false if not found, or the mime type string
if (lookedUpMimeType) {
if (lookedUpMimeType.startsWith('image/')) {
return 'image';