severo HF staff commited on
Commit
525089a
·
1 Parent(s): a53ca19

remove members of the huggingface org

Browse files
Files changed (1) hide show
  1. components/Content.tsx +58 -28
components/Content.tsx CHANGED
@@ -1,16 +1,12 @@
1
  import { Spinner } from './Spinner'
2
  import React, { useState, memo, useRef } from 'react'
3
  import debounce from 'debounce'
4
- import { cp } from 'fs'
5
 
6
- const usersCache = new Map<string, AccountDetails>()
7
 
8
  type AccountDetails = {
9
  user: string
10
  fullname: string
11
- // isFollowing: boolean
12
- // type: "user" | "org"
13
- // isPro: boolean
14
  avatarUrl: string
15
  followed_by: Set<string> // list of usernames
16
  followers_count: number
@@ -43,7 +39,6 @@ async function accountFollows(
43
  if (!page.map) {
44
  break
45
  }
46
- page = page.slice(0, limit)
47
  // const newData = await Promise.all(
48
  // page.map(async (account) => {
49
  // const user = account.user
@@ -62,6 +57,37 @@ async function accountFollows(
62
  return data
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  // async function accountFollowersCount(
66
  // handle: string,
67
  // logError: (x: string) => void
@@ -93,26 +119,26 @@ async function accountFollows(
93
  // return count
94
  // }
95
 
96
- async function accountDetails(
97
- handle: string,
98
- logError: (x: string) => void
99
- ): Promise<string> {
100
- let page
101
- try {
102
- let response = await fetch(
103
- `https://huggingface.co/api/users/${handle}/overview`
104
- )
105
-
106
- if (response.status !== 200) {
107
- throw new Error('HTTP request failed')
108
- }
109
- let page = await response.json()
110
- return page?.details ?? ''
111
- } catch (e) {
112
- logError(`Error while retrieving details for ${handle}.`)
113
- }
114
- return ''
115
- }
116
 
117
  async function accountFofs(
118
  handle: string,
@@ -120,12 +146,16 @@ async function accountFofs(
120
  setFollows: (x: Array<AccountDetails>) => void,
121
  logError: (x: string) => void
122
  ): Promise<void> {
 
123
  const directFollows = await accountFollows(handle, 2000, logError)
124
  setProgress([0, directFollows.length])
125
  let progress = 0
126
 
127
- const directFollowIds = new Set(directFollows.map(({ user }) => user))
128
- directFollowIds.add(handle)
 
 
 
129
 
130
  const indirectFollowLists: Array<Array<AccountDetails>> = []
131
 
 
1
  import { Spinner } from './Spinner'
2
  import React, { useState, memo, useRef } from 'react'
3
  import debounce from 'debounce'
 
4
 
5
+ // const usersCache = new Map<string, AccountDetails>()
6
 
7
  type AccountDetails = {
8
  user: string
9
  fullname: string
 
 
 
10
  avatarUrl: string
11
  followed_by: Set<string> // list of usernames
12
  followers_count: number
 
39
  if (!page.map) {
40
  break
41
  }
 
42
  // const newData = await Promise.all(
43
  // page.map(async (account) => {
44
  // const user = account.user
 
57
  return data
58
  }
59
 
60
+ async function organizationMembers(
61
+ organization: string,
62
+ logError: (x: string) => void
63
+ ): Promise<Array<string>> {
64
+ let nextPage:
65
+ | string
66
+ | null = `https://huggingface.co/api/organizations/${organization}/members`
67
+ let members: Array<string> = []
68
+ while (nextPage) {
69
+ console.log(`Get page: ${nextPage}`)
70
+ let response
71
+ let page
72
+ try {
73
+ response = await fetch(nextPage)
74
+ if (response.status !== 200) {
75
+ throw new Error('HTTP request failed')
76
+ }
77
+ page = await response.json()
78
+ } catch (e) {
79
+ logError(`Error while retrieving members for ${organization}.`)
80
+ break
81
+ }
82
+ if (!page.map) {
83
+ break
84
+ }
85
+ members = [...members, ...page.map(({ user }) => user)]
86
+ nextPage = getNextPage(response.headers.get('Link'))
87
+ }
88
+ return members
89
+ }
90
+
91
  // async function accountFollowersCount(
92
  // handle: string,
93
  // logError: (x: string) => void
 
119
  // return count
120
  // }
121
 
122
+ // async function accountDetails(
123
+ // handle: string,
124
+ // logError: (x: string) => void
125
+ // ): Promise<string> {
126
+ // let page
127
+ // try {
128
+ // let response = await fetch(
129
+ // `https://huggingface.co/api/users/${handle}/overview`
130
+ // )
131
+
132
+ // if (response.status !== 200) {
133
+ // throw new Error('HTTP request failed')
134
+ // }
135
+ // let page = await response.json()
136
+ // return page?.details ?? ''
137
+ // } catch (e) {
138
+ // logError(`Error while retrieving details for ${handle}.`)
139
+ // }
140
+ // return ''
141
+ // }
142
 
143
  async function accountFofs(
144
  handle: string,
 
146
  setFollows: (x: Array<AccountDetails>) => void,
147
  logError: (x: string) => void
148
  ): Promise<void> {
149
+ const hfMembers = await organizationMembers('huggingface', logError)
150
  const directFollows = await accountFollows(handle, 2000, logError)
151
  setProgress([0, directFollows.length])
152
  let progress = 0
153
 
154
+ const directFollowIds = new Set([
155
+ handle,
156
+ ...directFollows.map(({ user }) => user),
157
+ ...hfMembers,
158
+ ])
159
 
160
  const indirectFollowLists: Array<Array<AccountDetails>> = []
161