@samitouri / QOSami-HFS / commits / 69f9f8b8

fix: updating plugins with legacy versions (from api* branches) was not working, and latest was installed instead

Massimo Melina committed Jan 8, 2024 at 11:06 UTC 69f9f8b8df069a2e9bc6ec48aad8a11db671a038
2 files changed +8 -5
admin/src/InstalledPlugins.ts
+1 -1
@@ -52,7 +52,7 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
52 disabled: row.updated,
53 size,
54 async onClick() {
55 - await apiCall('update_plugin', { id }, { timeout: false }).catch(e => {
55 + await apiCall('update_plugin', { id, branch: row.branch }, { timeout: false }).catch(e => {
56 throw e.code !== HTTP_FAILED_DEPENDENCY ? e
57 : Error("Failed dependencies: " + e.cause?.map((x: any) => prefix(`plugin "`, x.id || x.repo, `" `) + x.error).join('; '))
58 })
src/api.plugins.ts
+7 -4
@@ -7,7 +7,7 @@ import {
7 } from './plugins'
8 import _ from 'lodash'
9 import assert from 'assert'
10 -import { Callback, newObj, onOff, waitFor } from './misc'
10 +import { Callback, HTTP_CONFLICT, newObj, onOff, waitFor } from './misc'
11 import { ApiError, ApiHandlers } from './apiMiddleware'
12 import events from './events'
13 import { rm } from 'fs/promises'
@@ -136,14 +136,17 @@ const apis: ApiHandlers = {
136 || new ApiError(HTTP_SERVER_ERROR)
137 },
138
139 - async update_plugin({ id }) {
139 + async update_plugin({ id, branch }) {
140 const found = getPluginInfo(id)
141 if (!found)
142 return new ApiError(HTTP_NOT_FOUND)
143 - await checkDependencies(found)
143 + const online = await readOnlineCompatiblePlugin(found.repo) // branch returned by readOnlineCompatiblePlugin is possibly fresher, so we use that
144 + if (!online)
145 + return new ApiError(HTTP_CONFLICT)
146 + await checkDependencies(online)
147 const enabled = isPluginEnabled(id)
148 await stopPlugin(id)
146 - await downloadPlugin(found.repo, { overwrite: true })
149 + await downloadPlugin(found.repo, { branch: online.branch, overwrite: true })
150 if (enabled)
151 startPlugin(id).then() // don't wait, in case it fails to start
152 return {}