@@ -15,6 +15,7 @@ import {
1515 extractCleanFilename ,
1616 extractStorageKey ,
1717 extractWorkspaceIdFromExecutionKey ,
18+ getMimeTypeFromExtension ,
1819 getViewerUrl ,
1920 inferContextFromKey ,
2021} from '@/lib/uploads/utils/file-utils'
@@ -44,36 +45,6 @@ interface ParseResult {
4445 }
4546}
4647
47- const fileTypeMap : Record < string , string > = {
48- // Text formats
49- txt : 'text/plain' ,
50- csv : 'text/csv' ,
51- json : 'application/json' ,
52- xml : 'application/xml' ,
53- md : 'text/markdown' ,
54- html : 'text/html' ,
55- css : 'text/css' ,
56- js : 'application/javascript' ,
57- ts : 'application/typescript' ,
58- // Document formats
59- pdf : 'application/pdf' ,
60- doc : 'application/msword' ,
61- docx : 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ,
62- // Spreadsheet formats
63- xls : 'application/vnd.ms-excel' ,
64- xlsx : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ,
65- // Presentation formats
66- ppt : 'application/vnd.ms-powerpoint' ,
67- pptx : 'application/vnd.openxmlformats-officedocument.presentationml.presentation' ,
68- // Image formats
69- png : 'image/png' ,
70- jpg : 'image/jpeg' ,
71- jpeg : 'image/jpeg' ,
72- gif : 'image/gif' ,
73- // Archive formats
74- zip : 'application/zip' ,
75- }
76-
7748/**
7849 * Main API route handler
7950 */
@@ -382,7 +353,8 @@ async function handleExternalUrl(
382353 } )
383354 } else {
384355 const { uploadWorkspaceFile } = await import ( '@/lib/uploads/contexts/workspace' )
385- const mimeType = response . headers . get ( 'content-type' ) || getMimeType ( extension )
356+ const mimeType =
357+ response . headers . get ( 'content-type' ) || getMimeTypeFromExtension ( extension )
386358 await uploadWorkspaceFile ( workspaceId , userId , buffer , filename , mimeType )
387359 logger . info ( `Saved URL file to workspace storage: ${ filename } ` )
388360 }
@@ -574,7 +546,7 @@ async function handleLocalFile(
574546 content : result . content ,
575547 filePath,
576548 metadata : {
577- fileType : fileType || getMimeType ( extension ) ,
549+ fileType : fileType || getMimeTypeFromExtension ( extension ) ,
578550 size : stats . size ,
579551 hash,
580552 processingTime : 0 ,
@@ -709,7 +681,7 @@ async function handleGenericTextBuffer(
709681 content : result . content ,
710682 filePath : originalPath || filename ,
711683 metadata : {
712- fileType : fileType || getMimeType ( extension ) ,
684+ fileType : fileType || getMimeTypeFromExtension ( extension ) ,
713685 size : fileBuffer . length ,
714686 hash : createHash ( 'md5' ) . update ( fileBuffer ) . digest ( 'hex' ) ,
715687 processingTime : 0 ,
@@ -727,7 +699,7 @@ async function handleGenericTextBuffer(
727699 content,
728700 filePath : originalPath || filename ,
729701 metadata : {
730- fileType : fileType || getMimeType ( extension ) ,
702+ fileType : fileType || getMimeTypeFromExtension ( extension ) ,
731703 size : fileBuffer . length ,
732704 hash : createHash ( 'md5' ) . update ( fileBuffer ) . digest ( 'hex' ) ,
733705 processingTime : 0 ,
@@ -768,7 +740,7 @@ function handleGenericBuffer(
768740 content,
769741 filePath : filename ,
770742 metadata : {
771- fileType : fileType || getMimeType ( extension ) ,
743+ fileType : fileType || getMimeTypeFromExtension ( extension ) ,
772744 size : fileBuffer . length ,
773745 hash : createHash ( 'md5' ) . update ( fileBuffer ) . digest ( 'hex' ) ,
774746 processingTime : 0 ,
@@ -791,13 +763,6 @@ async function parseBufferAsPdf(buffer: Buffer) {
791763 }
792764}
793765
794- /**
795- * Get MIME type from file extension
796- */
797- function getMimeType ( extension : string ) : string {
798- return fileTypeMap [ extension ] || 'application/octet-stream'
799- }
800-
801766/**
802767 * Format bytes to human readable size
803768 */
0 commit comments