@@ -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,9 @@ 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+
108112const isFileTooLarge = computed (() => {
109113 const size = currentNode .value ?.size
110114 return size !== undefined && size > MAX_FILE_SIZE
@@ -113,7 +117,13 @@ const isFileTooLarge = computed(() => {
113117// Fetch file content when a file is selected (and not too large)
114118const fileContentUrl = computed (() => {
115119 // Don't fetch if no file path, file tree not loaded, file is too large, or it's a directory
116- if (! filePath .value || ! fileTree .value || isFileTooLarge .value || ! isViewingFile .value ) {
120+ if (
121+ ! filePath .value ||
122+ ! fileTree .value ||
123+ isFileTooLarge .value ||
124+ ! isViewingFile .value ||
125+ isBinaryFile .value
126+ ) {
117127 return null
118128 }
119129 return ` /api/registry/file/${packageName .value }/v/${version .value }/${filePath .value } `
@@ -426,7 +436,7 @@ defineOgImageComponent('Default', {
426436 ref =" contentContainer"
427437 >
428438 <!-- File viewer -->
429- <template v-if =" isViewingFile && fileContent " >
439+ <template v-if =" isViewingFile && ! isBinaryFile && fileContent " >
430440 <div
431441 class =" sticky z-10 top-0 bg-bg border-b border-border px-4 py-2 flex items-center justify-between"
432442 >
@@ -519,6 +529,19 @@ defineOgImageComponent('Default', {
519529 />
520530 </template >
521531
532+ <!-- Binary file warning -->
533+ <div v-else-if =" isViewingFile && isBinaryFile" class =" py-20 text-center" >
534+ <div class =" i-lucide:binary w-12 h-12 mx-auto text-fg-subtle mb-4" />
535+ <p class =" text-fg-muted mb-2" >{{ $t('code.binary_file') }}</p >
536+ <p class =" text-fg-subtle text-sm mb-4" >{{ $t('code.binary_rendering_warning') }}</p >
537+ <LinkBase
538+ variant =" button-secondary"
539+ :to =" `https://cdn.jsdelivr.net/npm/${packageName}@${version}/${filePath}`"
540+ >
541+ {{ $t('code.view_raw') }}
542+ </LinkBase >
543+ </div >
544+
522545 <!-- File too large warning -->
523546 <div v-else-if =" isViewingFile && isFileTooLarge" class =" py-20 text-center" >
524547 <div class =" i-lucide:file-text w-12 h-12 mx-auto text-fg-subtle mb-4" />
0 commit comments