fix: HF token is not used while searching repositories

This commit is contained in:
Louis 2025-08-11 15:29:50 +07:00
parent 0bc1bf9f3d
commit c355649759
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
2 changed files with 13 additions and 3 deletions

View File

@ -39,6 +39,7 @@ import HeaderPage from '@/containers/HeaderPage'
import { Loader } from 'lucide-react' import { Loader } from 'lucide-react'
import { useTranslation } from '@/i18n/react-i18next-compat' import { useTranslation } from '@/i18n/react-i18next-compat'
import Fuse from 'fuse.js' import Fuse from 'fuse.js'
import { useGeneralSetting } from '@/hooks/useGeneralSetting'
type ModelProps = { type ModelProps = {
model: CatalogModel model: CatalogModel
@ -57,6 +58,7 @@ export const Route = createFileRoute(route.hub.index as any)({
function Hub() { function Hub() {
const parentRef = useRef(null) const parentRef = useRef(null)
const { huggingfaceToken } = useGeneralSetting()
const { t } = useTranslation() const { t } = useTranslation()
const sortOptions = [ const sortOptions = [
@ -185,7 +187,7 @@ function Hub() {
addModelSourceTimeoutRef.current = setTimeout(async () => { addModelSourceTimeoutRef.current = setTimeout(async () => {
try { try {
// Fetch HuggingFace repository information // Fetch HuggingFace repository information
const repoInfo = await fetchHuggingFaceRepo(e.target.value) const repoInfo = await fetchHuggingFaceRepo(e.target.value, huggingfaceToken)
if (repoInfo) { if (repoInfo) {
const catalogModel = convertHfRepoToCatalogModel(repoInfo) const catalogModel = convertHfRepoToCatalogModel(repoInfo)
if ( if (

View File

@ -99,7 +99,8 @@ export const fetchModelCatalog = async (): Promise<ModelCatalog> => {
* @returns A promise that resolves to the repository information. * @returns A promise that resolves to the repository information.
*/ */
export const fetchHuggingFaceRepo = async ( export const fetchHuggingFaceRepo = async (
repoId: string repoId: string,
hfToken?: string
): Promise<HuggingFaceRepo | null> => { ): Promise<HuggingFaceRepo | null> => {
try { try {
// Clean the repo ID to handle various input formats // Clean the repo ID to handle various input formats
@ -114,7 +115,14 @@ export const fetchHuggingFaceRepo = async (
} }
const response = await fetch( const response = await fetch(
`https://huggingface.co/api/models/${cleanRepoId}?blobs=true` `https://huggingface.co/api/models/${cleanRepoId}?blobs=true`,
{
headers: hfToken
? {
Authorization: `Bearer ${hfToken}`,
}
: {},
}
) )
if (!response.ok) { if (!response.ok) {