Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions components/object/preview-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ function getPreviewMode(hasPreviewUrl: boolean, canRenderText: boolean, canRende
return canRenderText ? "text" : "sandbox"
}

function isPdfPreview(contentType: string, objectKey: string) {
const keyLower = objectKey.toLowerCase()
return contentType === "application/pdf" || keyLower.endsWith(".pdf")
function isPdfPreview(contentType: string) {
return contentType === "application/pdf"
}

function isParquetPreview(contentType: string, objectKey: string) {
Expand Down Expand Up @@ -139,7 +138,7 @@ export function ObjectPreviewModal({ show, onShowChange, object }: ObjectPreview
const isJson = normalizedContentType === "application/json" || objectKeyLower.endsWith(".json")
const canRenderText = hasPreviewUrl && isSafeTextPreview(normalizedContentType, objectKey, objectSize)
const canRenderImage = hasPreviewUrl && isImagePreview(normalizedContentType, objectKey)
const canRenderPdf = hasPreviewUrl && isPdfPreview(normalizedContentType, objectKey)
const canRenderPdf = hasPreviewUrl && isPdfPreview(normalizedContentType)
const canRenderParquet = hasPreviewUrl && isParquetPreview(normalizedContentType, objectKey)
const previewMode: PreviewMode = canRenderParquet
? "parquet"
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/object-preview-source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ test("object preview modal falls back when standard fullscreen APIs are unavaila
assert.equal(source.includes("void document.exitFullscreen().catch(() => {})"), false)
assert.equal(source.includes("void container.requestFullscreen().catch(() => {})"), false)
})

test("object preview modal only uses the PDF viewer for application/pdf content", () => {
const source = fs.readFileSync("components/object/preview-modal.tsx", "utf8")

assert.match(
source,
/function isPdfPreview\(contentType: string\) \{\s+return contentType === "application\/pdf"\s+\}/,
)
assert.match(source, /isPdfPreview\(normalizedContentType\)/)
assert.doesNotMatch(source, /keyLower\.endsWith\("\.pdf"\)/)
})