@@ -100,7 +100,12 @@ const isViewingFile = computed(() => currentNode.value?.type === 'file')
100100// Maximum file size we'll try to load (500KB) - must match server
101101const MAX_FILE_SIZE = 500 * 1024
102102
103- const isBinaryFile = computed (() => !! filePath .value && isBinaryFilePath (filePath .value ))
103+ // Estimate binary file based on mime type
104+ const isBinaryFile = computed (() => {
105+ const contentType = fileContent .value ?.contentType
106+ if (! contentType ) return false
107+ return isBinaryContentType (contentType )
108+ })
104109
105110const isFileTooLarge = computed (() => {
106111 const size = currentNode .value ?.size
@@ -110,13 +115,7 @@ const isFileTooLarge = computed(() => {
110115// Fetch file content when a file is selected (and not too large)
111116const fileContentUrl = computed (() => {
112117 // Don't fetch if no file path, file tree not loaded, file is too large, or it's a directory
113- if (
114- ! filePath .value ||
115- ! fileTree .value ||
116- isFileTooLarge .value ||
117- ! isViewingFile .value ||
118- isBinaryFile .value
119- ) {
118+ if (! filePath .value || ! fileTree .value || isFileTooLarge .value || ! isViewingFile .value ) {
120119 return null
121120 }
122121 return ` /api/registry/file/${packageName .value }/v/${version .value }/${filePath .value } `
@@ -481,7 +480,13 @@ defineOgImageComponent('Default', {
481480 <div v-else-if =" isViewingFile && isBinaryFile" class =" py-20 text-center" >
482481 <div class =" i-lucide:binary w-12 h-12 mx-auto text-fg-subtle mb-4" />
483482 <p class =" text-fg-muted mb-2" >{{ $t('code.binary_file') }}</p >
484- <p class =" text-fg-subtle text-sm mb-4" >{{ $t('code.binary_rendering_warning') }}</p >
483+ <p class =" text-fg-subtle text-sm mb-4" >
484+ {{
485+ $t('code.binary_rendering_warning', {
486+ contentType: fileContent?.contentType ?? 'unknown',
487+ })
488+ }}
489+ </p >
485490 <LinkBase
486491 variant =" button-secondary"
487492 :to =" `https://cdn.jsdelivr.net/npm/${packageName}@${version}/${filePath}`"
0 commit comments