@@ -4,7 +4,6 @@ import type {
44 PackageFileTreeResponse ,
55 PackageFileContentResponse ,
66} from ' #shared/types'
7- import { isBinaryFilePath } from ' ~/utils/file-types'
87
98definePageMeta ({
109 name: ' code' ,
@@ -107,7 +106,12 @@ const isViewingFile = computed(() => currentNode.value?.type === 'file')
107106// Maximum file size we'll try to load (500KB) - must match server
108107const MAX_FILE_SIZE = 500 * 1024
109108
110- const isBinaryFile = computed (() => !! filePath .value && isBinaryFilePath (filePath .value ))
109+ // Estimate binary file based on mime type
110+ const isBinaryFile = computed (() => {
111+ const contentType = fileContent .value ?.contentType
112+ if (! contentType ) return false
113+ return isBinaryContentType (contentType )
114+ })
111115
112116const isFileTooLarge = computed (() => {
113117 const size = currentNode .value ?.size
@@ -117,13 +121,7 @@ const isFileTooLarge = computed(() => {
117121// Fetch file content when a file is selected (and not too large)
118122const fileContentUrl = computed (() => {
119123 // Don't fetch if no file path, file tree not loaded, file is too large, or it's a directory
120- if (
121- ! filePath .value ||
122- ! fileTree .value ||
123- isFileTooLarge .value ||
124- ! isViewingFile .value ||
125- isBinaryFile .value
126- ) {
124+ if (! filePath .value || ! fileTree .value || isFileTooLarge .value || ! isViewingFile .value ) {
127125 return null
128126 }
129127 return ` /api/registry/file/${packageName .value }/v/${version .value }/${filePath .value } `
@@ -533,7 +531,13 @@ defineOgImageComponent('Default', {
533531 <div v-else-if =" isViewingFile && isBinaryFile" class =" py-20 text-center" >
534532 <div class =" i-lucide:binary w-12 h-12 mx-auto text-fg-subtle mb-4" />
535533 <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 >
534+ <p class =" text-fg-subtle text-sm mb-4" >
535+ {{
536+ $t('code.binary_rendering_warning', {
537+ contentType: fileContent?.contentType ?? 'unknown',
538+ })
539+ }}
540+ </p >
537541 <LinkBase
538542 variant =" button-secondary"
539543 :to =" `https://cdn.jsdelivr.net/npm/${packageName}@${version}/${filePath}`"
0 commit comments