import React, { lazy, Suspense } from 'react'; import type { INode } from '@/modules/storage/types'; import { getExt, isTextViewable, getMimeCategory } from '@/modules/storage/helpers'; import ImageLightbox from '@/components/ImageLightbox'; import LightboxIframe from '@/modules/storage/views/LightboxIframe'; import LightboxText from '@/modules/storage/views/LightboxText'; import { Loader2 } from 'lucide-react'; import { T } from '@/i18n'; const PdfLightbox = lazy(() => import('@/modules/storage/views/PdfLightbox')); const SpreadsheetLightbox = lazy(() => import('@/modules/storage/views/SpreadsheetLightbox')); const ThreeDViewer = lazy(() => import('@/modules/storage/views/ThreeDViewer')); export interface SharedViewerProps { isOpen: boolean; onClose: () => void; url: string; inline?: boolean; fileName?: string; selected: INode; onLinkClick?: (href: string, e: React.MouseEvent) => void; } export function renderFileViewer(props: SharedViewerProps) { const { selected, url, fileName, inline, isOpen, onClose, onLinkClick } = props; const cat = getMimeCategory(selected); // Mime categorization isn't strong enough on its own, so we augment with extension const ext = getExt(selected.name); if ((cat === 'image' || cat === 'video' || ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif', 'mp4', 'webm', 'ogg', 'mov'].includes(ext)) && ext !== 'dxf' && ext !== 'svg') { return ( ); } if (ext === 'html' || ext === 'htm') { return ( ); } if (ext === 'pdf') { return ( Loading PDF viewer... }> ); } if (['csv', 'xls', 'xlsx'].includes(ext)) { return ( Loading Spreadsheet viewer... }> ); } if (['stl', 'obj', 'step', 'stp', 'dxf'].includes(ext)) { const maxSize = ext === 'stl' ? 8 * 1024 * 1024 : 3 * 1024 * 1024; if (typeof selected.size === 'number' && selected.size > maxSize) { return (
File too large to preview in 3D ({(selected.size / (1024 * 1024)).toFixed(2)} MB / Max {(maxSize / (1024 * 1024)).toFixed(0)}.00 MB)
); } return ( Loading 3D Engine... }> ); } if (isTextViewable(selected)) { return ( ); } // Binary file or unsupported file limit reached if (typeof selected.size === 'number' && selected.size > 2 * 1024 * 1024) { return (
File too large to preview ({(selected.size / (1024 * 1024)).toFixed(2)} MB)
); } return
Unsupported file format
; }