@samitouri / QOSami-HFS / commits / a44ab330

admin/plugins: faster search online

Massimo Melina committed May 7, 2024 at 16:32 UTC a44ab3305ffd85d0eeb92f1dfe2fbe5ebccb5f2b
2 files changed +4 -5
src/api.plugins.ts
+2 -3
@@ -99,10 +99,9 @@ const apis: ApiHandlers = {
99 const undo: Callback[] = []
100 ctx.req.once('close', () => undo.forEach(x => x()))
101
102 - const folder2repo = getFolder2repo()
103 - for await (const pl of await searchPlugins(text)) {
102 + const already = Object.values(getFolder2repo()).map(String)
103 + for await (const pl of await searchPlugins(text, { skipRepos: already })) {
104 const repo = pl.repo || pl.id // .repo property can be more trustworthy in case github user renamed and left the previous link in 'repo'
105 - if (_.includes(folder2repo, repo)) continue // don't include installed plugins
105 const missing = await getMissingDependencies(pl)
106 if (missing.length) pl.missing = missing
107 list.add(pl)
src/github.ts
+2 -2
@@ -158,12 +158,12 @@ async function apiGithub(uri: string) {
158 })
159 }
160
161 -export async function searchPlugins(text='') {
161 +export async function searchPlugins(text='', { skipRepos=[''] }={}) {
162 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) => {
165 const repo = it.full_name as string
166 - if (projectInfo?.plugins_blacklist?.includes(repo)) return
166 + if (projectInfo?.plugins_blacklist?.includes(repo) || skipRepos.includes(repo)) return
167 const pl = await readOnlineCompatiblePlugin(repo, it.default_branch).catch(() => undefined)
168 if (!pl) return
169 Object.assign(pl, { // inject some extra useful fields