fix: weird HF readme accessibility

This commit is contained in:
Louis 2025-08-12 12:46:26 +07:00
parent 1a72a592b9
commit 7b2d0432e6
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -156,12 +156,19 @@ function HubModelDetail() {
useEffect(() => { useEffect(() => {
if (modelData?.readme) { if (modelData?.readme) {
setIsLoadingReadme(true) setIsLoadingReadme(true)
fetch(modelData.readme, { // Try fetching without headers first
headers: huggingfaceToken // There is a weird issue where this HF link will return error when access public repo with auth header
? { fetch(modelData.readme)
.then((response) => {
if (!response.ok && huggingfaceToken && modelData?.readme) {
// Retry with Authorization header if first fetch failed
return fetch(modelData.readme, {
headers: {
Authorization: `Bearer ${huggingfaceToken}`, Authorization: `Bearer ${huggingfaceToken}`,
},
})
} }
: {}, return response
}) })
.then((response) => response.text()) .then((response) => response.text())
.then((content) => { .then((content) => {