@@ -7,13 +7,14 @@ import { Spinner } from "@/components/ui/spinner"
77import { Button } from "@/components/ui/button"
88import { cn } from "@/lib/utils"
99import { RiFullscreenExitLine , RiFullscreenLine } from "@remixicon/react"
10+ import { PdfViewer } from "@/components/object/pdf-viewer"
1011
1112const SAFE_TEXT_MIMES = [ "application/json" , "application/xml" , "text/plain" , "text/xml" , "text/csv" , "text/markdown" ]
1213const SAFE_TEXT_EXTENSIONS = [ ".txt" , ".json" , ".xml" , ".csv" , ".md" , ".yml" , ".yaml" ]
1314const SAFE_IMAGE_EXTENSIONS = [ ".png" , ".jpg" , ".jpeg" , ".gif" , ".webp" , ".bmp" , ".ico" , ".tif" , ".tiff" ]
1415const ALLOWED_SIZE = 1024 * 1024 * 2 // 2MB
1516
16- type PreviewMode = "text" | "image" | "sandbox" | "download"
17+ type PreviewMode = "text" | "image" | "pdf" | " sandbox" | "download"
1718
1819interface ObjectPreviewModalProps {
1920 show : boolean
@@ -51,6 +52,11 @@ function getPreviewMode(hasPreviewUrl: boolean, canRenderText: boolean, canRende
5152 return canRenderText ? "text" : "sandbox"
5253}
5354
55+ function isPdfPreview ( contentType : string , objectKey : string ) {
56+ const keyLower = objectKey . toLowerCase ( )
57+ return contentType === "application/pdf" || keyLower . endsWith ( ".pdf" )
58+ }
59+
5460export function ObjectPreviewModal ( { show, onShowChange, object } : ObjectPreviewModalProps ) {
5561 const { t } = useTranslation ( )
5662 const [ textContent , setTextContent ] = React . useState ( "" )
@@ -75,7 +81,8 @@ export function ObjectPreviewModal({ show, onShowChange, object }: ObjectPreview
7581 const isJson = normalizedContentType === "application/json" || objectKeyLower . endsWith ( ".json" )
7682 const canRenderText = hasPreviewUrl && isSafeTextPreview ( normalizedContentType , objectKey , objectSize )
7783 const canRenderImage = hasPreviewUrl && isImagePreview ( normalizedContentType , objectKey )
78- const previewMode = getPreviewMode ( hasPreviewUrl , canRenderText , canRenderImage )
84+ const canRenderPdf = hasPreviewUrl && isPdfPreview ( normalizedContentType , objectKey )
85+ const previewMode = canRenderPdf ? "pdf" : getPreviewMode ( hasPreviewUrl , canRenderText , canRenderImage )
7986 const isImageMode = previewMode === "image"
8087
8188 const getFormattedContent = ( ) => {
@@ -276,6 +283,8 @@ export function ObjectPreviewModal({ show, onShowChange, object }: ObjectPreview
276283 return (
277284 < iframe src = { previewUrl } className = "h-[70vh] w-full" frameBorder = { 0 } title = "Sandbox preview" sandbox = "" />
278285 )
286+ case "pdf" :
287+ return < PdfViewer url = { previewUrl } />
279288 case "download" :
280289 default :
281290 return (
0 commit comments