Viani commited on
Commit
2f80fef
·
1 Parent(s): 715230e

fix: resolve canonical HF username before fetching models

Browse files

The HF models/datasets/spaces API is case-sensitive (e.g. "AMD" returns
0 results but "amd" returns 379). Now resolves the canonical name from
the org/user API first, then uses it for all data fetches.

src/components/UserSearchDialog.tsx CHANGED
@@ -29,11 +29,13 @@ const UserSearchDialog = () => {
29
  if (searchInput.trim()) {
30
  setIsLoading(true);
31
  try {
32
- const authorData = await fetchAllAuthorsData([searchInput.trim()]);
33
  const authorInfo = await fetchOrganizationData([searchInput.trim()]);
 
 
 
34
  setSearchedData(authorData);
35
  setUserInfo(authorInfo);
36
- setCurrentSearchTerm(searchInput.trim());
37
  } catch (error) {
38
  console.error("Error fetching data for searched user:", error);
39
  setSearchedData(null);
 
29
  if (searchInput.trim()) {
30
  setIsLoading(true);
31
  try {
 
32
  const authorInfo = await fetchOrganizationData([searchInput.trim()]);
33
+ const resolvedName =
34
+ authorInfo.authorsData?.[0]?.author || searchInput.trim();
35
+ const authorData = await fetchAllAuthorsData([resolvedName]);
36
  setSearchedData(authorData);
37
  setUserInfo(authorInfo);
38
+ setCurrentSearchTerm(resolvedName);
39
  } catch (error) {
40
  console.error("Error fetching data for searched user:", error);
41
  setSearchedData(null);
src/pages/[author]/index.tsx CHANGED
@@ -58,22 +58,22 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
58
  const authorColor = (color as string) || DEFAULT_COLOR;
59
 
60
  try {
61
- const { fullName, avatarUrl } = await fetchOrganizationData([
62
- author as string,
63
- ]);
64
 
65
  const providers: Record<string, AuthorPageProvider> = {
66
- [author as string]: {
67
  color: authorColor,
68
- authors: [author as string],
69
- fullName,
70
- avatarUrl,
71
  },
72
  };
73
 
74
- const flatData = await fetchAuthorData(author as string);
75
  const calendarData = generateCalendarData(flatData, [
76
- providers[author as string],
77
  ]);
78
 
79
  return {
 
58
  const authorColor = (color as string) || DEFAULT_COLOR;
59
 
60
  try {
61
+ const orgData = await fetchOrganizationData([author as string]);
62
+ const resolvedName =
63
+ orgData.authorsData?.[0]?.author || (author as string);
64
 
65
  const providers: Record<string, AuthorPageProvider> = {
66
+ [resolvedName]: {
67
  color: authorColor,
68
+ authors: [resolvedName],
69
+ fullName: orgData.fullName,
70
+ avatarUrl: orgData.avatarUrl,
71
  },
72
  };
73
 
74
+ const flatData = await fetchAuthorData(resolvedName);
75
  const calendarData = generateCalendarData(flatData, [
76
+ providers[resolvedName],
77
  ]);
78
 
79
  return {
src/utils/authors.ts CHANGED
@@ -41,20 +41,20 @@ const transformApiData = (author: string, data: any, isOrganization: boolean): A
41
 
42
  async function fetchSingleAuthorData(author: string): Promise<AuthorData> {
43
  try {
44
- // Try organizations API first
45
  const orgResponse = await fetch(`https://huggingface.co/api/organizations/${author}/overview`);
46
  if (orgResponse.ok) {
47
  const data = await orgResponse.json();
48
- return transformApiData(author, data, true);
 
49
  }
50
-
51
- // Fallback to users API
52
  const userResponse = await fetch(`https://huggingface.co/api/users/${author}/overview`);
53
  if (userResponse.ok) {
54
  const data = await userResponse.json();
55
- return transformApiData(author, data, false);
 
56
  }
57
-
58
  throw new Error('Neither organization nor user API returned valid data');
59
  } catch (error) {
60
  console.error(`Error fetching data for ${author}:`, error);
 
41
 
42
  async function fetchSingleAuthorData(author: string): Promise<AuthorData> {
43
  try {
 
44
  const orgResponse = await fetch(`https://huggingface.co/api/organizations/${author}/overview`);
45
  if (orgResponse.ok) {
46
  const data = await orgResponse.json();
47
+ const canonicalName = data.name || author;
48
+ return transformApiData(canonicalName, data, true);
49
  }
50
+
 
51
  const userResponse = await fetch(`https://huggingface.co/api/users/${author}/overview`);
52
  if (userResponse.ok) {
53
  const data = await userResponse.json();
54
+ const canonicalName = data.user || author;
55
+ return transformApiData(canonicalName, data, false);
56
  }
57
+
58
  throw new Error('Neither organization nor user API returned valid data');
59
  } catch (error) {
60
  console.error(`Error fetching data for ${author}:`, error);