@@ -17,21 +17,20 @@ export default function FilePreviewModal({ isOpen, onClose, fileUrl, fileName, f
1717 const isImage = fileType . includes ( "image" ) ;
1818 const isVideo = fileType . includes ( "video" ) ;
1919 const isPDF = fileType . includes ( "pdf" ) ;
20- // Simple check for office files based on type or extension if needed,
21- // but usually these have specific mime types or we can imply from extension in name.
22- // Common Office Mime Types:
23- // application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document
24- // application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
25- // application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation
26- const isOffice =
27- fileType . includes ( "word" ) ||
28- fileType . includes ( "excel" ) ||
29- fileType . includes ( "spreadsheet" ) ||
30- fileType . includes ( "powerpoint" ) ||
31- fileType . includes ( "presentation" ) ||
32- fileName . endsWith ( ".doc" ) || fileName . endsWith ( ".docx" ) ||
33- fileName . endsWith ( ".xls" ) || fileName . endsWith ( ".xlsx" ) ||
34- fileName . endsWith ( ".ppt" ) || fileName . endsWith ( ".pptx" ) ;
20+
21+ // Generic check for any document that isn't media or PDF
22+ // Google Viewer supports many formats including .ai, .psd, .dxf, .svg, .eps, .ps, .ttf, .xps, .zip, .rar
23+ const isGoogleDocSupported =
24+ ! isImage &&
25+ ! isVideo &&
26+ ! isPDF &&
27+ (
28+ fileType . includes ( "application/" ) ||
29+ fileType . includes ( "text/" ) ||
30+ fileName . match ( / \. ( d o c | d o c x | x l s | x l s x | p p t | p p t x | t x t | r t f | c s v | o d t | o d s | o d p | a i | p s d | d x f | e p s | p s | x p s | t t f | p a g e s | n u m b e r s | k e y ) $ / i)
31+ ) ;
32+
33+ const showGoogleViewer = isGoogleDocSupported ;
3534
3635 return (
3736 < div style = { {
@@ -76,14 +75,15 @@ export default function FilePreviewModal({ isOpen, onClose, fileUrl, fileName, f
7675 < PDFViewer fileUrl = { fileUrl } fileName = { fileName } />
7776 ) }
7877
79- { isOffice && (
78+ { showGoogleViewer && (
8079 < iframe
81- src = { `https://docs.google.com/gview ?url=${ encodeURIComponent ( fileUrl ) } &embedded=true` }
80+ src = { `https://docs.google.com/viewer ?url=${ encodeURIComponent ( fileUrl ) } &embedded=true` }
8281 style = { { width : "100%" , height : "100%" , border : "none" } }
82+ title = "Document Preview"
8383 />
8484 ) }
8585
86- { ! isImage && ! isVideo && ! isPDF && ! isOffice && (
86+ { ! isImage && ! isVideo && ! isPDF && ! showGoogleViewer && (
8787 < div style = { { textAlign : "center" , color : "#64748b" } } >
8888 < p style = { { marginBottom : "1rem" } } > Preview not available for this file type.</ p >
8989 < a href = { fileUrl } download className = "btn btn-primary" style = { { display : "inline-flex" , alignItems : "center" , gap : "0.5rem" , padding : "0.5rem 1rem" , background : "#2563eb" , color : "white" , borderRadius : "6px" , textDecoration : "none" } } >
0 commit comments