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,13 +156,20 @@ function HubModelDetail() {
useEffect(() => {
if (modelData?.readme) {
setIsLoadingReadme(true)
fetch(modelData.readme, {
headers: huggingfaceToken
? {
Authorization: `Bearer ${huggingfaceToken}`,
}
: {},
})
// Try fetching without headers first
// 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}`,
},
})
}
return response
})
.then((response) => response.text())
.then((content) => {
setReadmeContent(content)