@@ -4,6 +4,7 @@ import type {
44 PackageFileTreeResponse ,
55 PackageFileContentResponse ,
66} from ' #shared/types'
7+ import { isBinaryFilePath } from ' ~/utils/file-types'
78
89definePageMeta ({
910 name: ' code' ,
@@ -105,6 +106,14 @@ const isViewingFile = computed(() => currentNode.value?.type === 'file')
105106
106107// Maximum file size we'll try to load (500KB) - must match server
107108const MAX_FILE_SIZE = 500 * 1024
109+
110+ const isBinaryFile = computed (() => !! filePath .value && isBinaryFilePath (filePath .value ))
111+ const showBinaryContent = shallowRef (false )
112+
113+ watch (filePath , () => {
114+ showBinaryContent .value = false
115+ })
116+
108117const isFileTooLarge = computed (() => {
109118 const size = currentNode .value ?.size
110119 return size !== undefined && size > MAX_FILE_SIZE
@@ -116,6 +125,10 @@ const fileContentUrl = computed(() => {
116125 if (! filePath .value || ! fileTree .value || isFileTooLarge .value || ! isViewingFile .value ) {
117126 return null
118127 }
128+ // Don't fetch binary files until user explicitly requests rendering
129+ if (isBinaryFile .value && ! showBinaryContent .value ) {
130+ return null
131+ }
119132 return ` /api/registry/file/${packageName .value }/v/${version .value }/${filePath .value } `
120133})
121134
@@ -519,6 +532,25 @@ defineOgImageComponent('Default', {
519532 />
520533 </template >
521534
535+ <!-- Binary file placeholder -->
536+ <div
537+ v-else-if =" isViewingFile && isBinaryFile && !showBinaryContent"
538+ class =" py-20 text-center"
539+ >
540+ <div class =" i-lucide:binary w-12 h-12 mx-auto text-fg-subtle mb-4" />
541+ <p class =" text-fg-muted mb-2" >Binary file</p >
542+ <p class =" text-fg-subtle text-sm mb-4" >Rendering may produce garbled output.</p >
543+ <div class =" flex items-center justify-center gap-3" >
544+ <ButtonBase @click =" showBinaryContent = true" > Render anyway </ButtonBase >
545+ <LinkBase
546+ variant =" button-secondary"
547+ :to =" `https://cdn.jsdelivr.net/npm/${packageName}@${version}/${filePath}`"
548+ >
549+ View raw file
550+ </LinkBase >
551+ </div >
552+ </div >
553+
522554 <!-- File too large warning -->
523555 <div v-else-if =" isViewingFile && isFileTooLarge" class =" py-20 text-center" >
524556 <div class =" i-lucide:file-text w-12 h-12 mx-auto text-fg-subtle mb-4" />
0 commit comments