fix: admin/plugins/updates: was not considering api-compatibility branches
Massimo Melina committed
Dec 10, 2023 at 13:11 UTC
5a953c8aedf89f6652707ee7b4db28d3aa1593af
2 files changed
+28
-39
src/api.plugins.ts
+3
-4
@@ -11,7 +11,7 @@ import { Callback, newObj, onOff, waitFor } from './misc'
11
import { ApiError, ApiHandlers, SendListReadable } from './apiMiddleware'
12
import events from './events'
13
import { rm } from 'fs/promises'
14
-import { downloadPlugin, getFolder2repo, readOnlinePlugin, searchPlugins } from './github'
14
+import { downloadPlugin, getFolder2repo, readOnlineCompatiblePlugin, readOnlinePlugin, searchPlugins } from './github'
15
import { HTTP_FAILED_DEPENDENCY, HTTP_NOT_FOUND, HTTP_SERVER_ERROR } from './const'
16
17
const apis: ApiHandlers = {
@@ -35,9 +35,8 @@ const apis: ApiHandlers = {
35
await Promise.allSettled(_.map(getFolder2repo(), async (repo, folder) => {
36
try {
37
if (!repo) return
38
- //TODO shouldn't we consider other branches here?
39
- const online = await readOnlinePlugin(repo)
40
- if (!online?.apiRequired || online.badApi) return
38
+ const online = await readOnlineCompatiblePlugin(repo)
39
+ if (!online) return
40
const disk = getPluginInfo(folder)
41
if (!disk) return // plugin removed in the meantime?
42
if (online.version! > disk.version) { // it IS newer
src/github.ts
+25
-35
@@ -2,25 +2,12 @@
2
3
import events from './events'
4
import { DAY, httpString, httpStream, unzip, AsapStream, debounceAsync } from './misc'
5
-import {
6
- DISABLING_POSTFIX, findPluginByRepo,
7
- getAvailablePlugins,
8
- getPluginInfo,
9
- mapPlugins,
10
- parsePluginSource,
11
- PATH as PLUGINS_PATH, Repo,
12
-} from './plugins'
5
+import { DISABLING_POSTFIX, findPluginByRepo, getAvailablePlugins, getPluginInfo, mapPlugins,
6
+ parsePluginSource, PATH as PLUGINS_PATH, Repo } from './plugins'
7
import { ApiError } from './apiMiddleware'
8
import _ from 'lodash'
15
-import {
16
- DEV,
17
- HFS_REPO,
18
- HFS_REPO_BRANCH,
19
- HTTP_BAD_REQUEST,
20
- HTTP_CONFLICT, HTTP_FORBIDDEN,
21
- HTTP_NOT_ACCEPTABLE,
22
- HTTP_SERVER_ERROR
23
-} from './const'
9
+import { DEV, HFS_REPO, HFS_REPO_BRANCH, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_NOT_ACCEPTABLE,
10
+ HTTP_SERVER_ERROR } from './const'
11
import { rename, rm } from 'fs/promises'
12
import { join } from 'path'
13
import { readFileSync } from 'fs'
@@ -134,6 +121,25 @@ export async function readOnlinePlugin(repo: Repo, branch='') {
121
return pl
122
}
123
124
+export async function readOnlineCompatiblePlugin(repo: Repo, branch='') {
125
+ const pl = await readOnlinePlugin(repo, branch)
126
+ if (!pl?.apiRequired) return // mandatory field
127
+ if (!pl.badApi) return pl
128
+ // we try other branches (starting with 'api')
129
+ const res = await apiGithub('repos/' + repo + '/branches')
130
+ const branches: string[] = res.map((x: any) => x?.name)
131
+ .filter((x: any) => typeof x === 'string' && x.startsWith('api'))
132
+ .sort().reverse()
133
+ for (const branch of branches) {
134
+ const pl = await readOnlinePlugin(repo, branch)
135
+ if (!pl) continue
136
+ if (!pl.apiRequired)
137
+ pl.badApi = '-'
138
+ if (!pl.badApi)
139
+ return pl
140
+ }
141
+}
142
+
143
export function getFolder2repo() {
144
const ret = Object.fromEntries(getAvailablePlugins().map(x => [x.id, x.repo]))
145
Object.assign(ret, Object.fromEntries(mapPlugins(x => [x.id, x.getData().repo])))
@@ -159,24 +165,8 @@ export async function searchPlugins(text='') {
165
return new AsapStream(list.items.map(async (it: any) => {
166
const repo = it.full_name as string
167
if (projectInfo?.plugins_blacklist?.includes(repo)) return
162
- let pl = await readOnlinePlugin(repo, it.default_branch)
163
- if (!pl?.apiRequired) return // mandatory field
164
- if (pl.badApi) { // we try other branches (starting with 'api')
165
- const res = await apiGithub('repos/' + repo + '/branches')
166
- const branches: string[] = res.map((x: any) => x?.name)
167
- .filter((x: any) => typeof x === 'string' && x.startsWith('api'))
168
- .sort().reverse()
169
- for (const branch of branches) {
170
- pl = await readOnlinePlugin(repo, branch)
171
- if (!pl) continue
172
- if (!pl.apiRequired)
173
- pl.badApi = '-'
174
- if (!pl.badApi)
175
- break
176
- }
177
- }
178
- if (!pl || pl.badApi)
179
- return
168
+ const pl = await readOnlineCompatiblePlugin(repo, it.default_branch)
169
+ if (!pl) return
170
Object.assign(pl, { // inject some extra useful fields
171
downloading: downloading[repo],
172
license: it.license?.spdx_id,