@@ -27,6 +27,7 @@ import {
2727import { Progress } from '@/components/ui/progress'
2828import { Button } from '@/components/ui/button'
2929import { cn } from '@/lib/utils'
30+ import { useGeneralSetting } from '@/hooks/useGeneralSetting'
3031
3132type SearchParams = {
3233 repo : string
@@ -42,6 +43,7 @@ export const Route = createFileRoute('/hub/$modelId')({
4243function HubModelDetail ( ) {
4344 const { modelId } = useParams ( { from : Route . id } )
4445 const navigate = useNavigate ( )
46+ const { huggingfaceToken } = useGeneralSetting ( )
4547 const { sources, fetchSources } = useModelSources ( )
4648 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4749 const search = useSearch ( { from : Route . id as any } )
@@ -60,12 +62,15 @@ function HubModelDetail() {
6062 } , [ fetchSources ] )
6163
6264 const fetchRepo = useCallback ( async ( ) => {
63- const repoInfo = await fetchHuggingFaceRepo ( search . repo || modelId )
65+ const repoInfo = await fetchHuggingFaceRepo (
66+ search . repo || modelId ,
67+ huggingfaceToken
68+ )
6469 if ( repoInfo ) {
6570 const repoDetail = convertHfRepoToCatalogModel ( repoInfo )
6671 setRepoData ( repoDetail )
6772 }
68- } , [ modelId , search ] )
73+ } , [ modelId , search , huggingfaceToken ] )
6974
7075 useEffect ( ( ) => {
7176 fetchRepo ( )
@@ -151,7 +156,20 @@ function HubModelDetail() {
151156 useEffect ( ( ) => {
152157 if ( modelData ?. readme ) {
153158 setIsLoadingReadme ( true )
159+ // Try fetching without headers first
160+ // There is a weird issue where this HF link will return error when access public repo with auth header
154161 fetch ( modelData . readme )
162+ . then ( ( response ) => {
163+ if ( ! response . ok && huggingfaceToken && modelData ?. readme ) {
164+ // Retry with Authorization header if first fetch failed
165+ return fetch ( modelData . readme , {
166+ headers : {
167+ Authorization : `Bearer ${ huggingfaceToken } ` ,
168+ } ,
169+ } )
170+ }
171+ return response
172+ } )
155173 . then ( ( response ) => response . text ( ) )
156174 . then ( ( content ) => {
157175 setReadmeContent ( content )
@@ -162,7 +180,7 @@ function HubModelDetail() {
162180 setIsLoadingReadme ( false )
163181 } )
164182 }
165- } , [ modelData ?. readme ] )
183+ } , [ modelData ?. readme , huggingfaceToken ] )
166184
167185 if ( ! modelData ) {
168186 return (
0 commit comments