fix: admin/plugins/search: was not reporting all plugins
Massimo Melina committed
May 7, 2024 at 16:33 UTC
80807e313e35d73e34a77f5103d9bdece24a043f
1 file changed
+17
-3
src/github.ts
+17
-3
@@ -1,7 +1,7 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
import events from './events'
4
-import { DAY, httpString, httpStream, unzip, AsapStream, debounceAsync } from './misc'
4
+import { DAY, httpString, httpStream, unzip, AsapStream, debounceAsync, asyncGeneratorToArray } from './misc'
5
import { DISABLING_SUFFIX, findPluginByRepo, getAvailablePlugins, getPluginInfo, mapPlugins,
6
parsePluginSource, PATH as PLUGINS_PATH, Repo } from './plugins'
7
import { ApiError } from './apiMiddleware'
@@ -158,10 +158,24 @@ async function apiGithub(uri: string) {
158
})
159
}
160
161
+async function *apiGithubPaginated<T=any>(uri: string) {
162
+ const PAGE_SIZE = 100
163
+ let page = 1
164
+ let n = 0
165
+ while (1) {
166
+ const res = await apiGithub(uri + `&page=${page++}&per_page=${PAGE_SIZE}`)
167
+ for (const x of res.items)
168
+ yield x as T
169
+ const now = res.items.length
170
+ n += now
171
+ if (!now || n >= res.total_count) break
172
+ }
173
+}
174
+
175
export async function searchPlugins(text='', { skipRepos=[''] }={}) {
176
const projectInfo = await getProjectInfo()
163
- const list = await apiGithub('search/repositories?q=topic:hfs-plugin+' + encodeURI(text))
164
- return new AsapStream(list.items.map(async (it: any) => {
177
+ const list = await asyncGeneratorToArray(apiGithubPaginated(`search/repositories?q=topic:hfs-plugin+` + encodeURI(text)))
178
+ return new AsapStream(list.map(async it => { // using AsapStream we parallelize these promises and produce each result as it's ready
179
const repo = it.full_name as string
180
if (projectInfo?.plugins_blacklist?.includes(repo) || skipRepos.includes(repo)) return
181
const pl = await readOnlineCompatiblePlugin(repo, it.default_branch).catch(() => undefined)