diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/plugins/plugin-index.ts | 12 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 9 | ||||
-rw-r--r-- | server/lib/plugins/yarn.ts | 13 |
3 files changed, 28 insertions, 6 deletions
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts index 624f5da1d..165bc91b3 100644 --- a/server/lib/plugins/plugin-index.ts +++ b/server/lib/plugins/plugin-index.ts | |||
@@ -67,7 +67,19 @@ async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePlu | |||
67 | return body | 67 | return body |
68 | } | 68 | } |
69 | 69 | ||
70 | async function getLatestPluginVersion (npmName: string) { | ||
71 | const results = await getLatestPluginsVersion([ npmName ]) | ||
72 | |||
73 | if (Array.isArray(results) === false || results.length !== 1) { | ||
74 | logger.warn('Cannot get latest supported plugin version of %s.', npmName) | ||
75 | return undefined | ||
76 | } | ||
77 | |||
78 | return results[0].latestVersion | ||
79 | } | ||
80 | |||
70 | export { | 81 | export { |
71 | listAvailablePluginsFromIndex, | 82 | listAvailablePluginsFromIndex, |
83 | getLatestPluginVersion, | ||
72 | getLatestPluginsVersion | 84 | getLatestPluginsVersion |
73 | } | 85 | } |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index e3226a950..03ea48416 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -328,11 +328,18 @@ export class PluginManager implements ServerHook { | |||
328 | return plugin | 328 | return plugin |
329 | } | 329 | } |
330 | 330 | ||
331 | async update (toUpdate: string, version?: string, fromDisk = false) { | 331 | async update (toUpdate: string, fromDisk = false) { |
332 | const npmName = fromDisk ? basename(toUpdate) : toUpdate | 332 | const npmName = fromDisk ? basename(toUpdate) : toUpdate |
333 | 333 | ||
334 | logger.info('Updating plugin %s.', npmName) | 334 | logger.info('Updating plugin %s.', npmName) |
335 | 335 | ||
336 | // Use the latest version from DB, to not upgrade to a version that does not support our PeerTube version | ||
337 | let version: string | ||
338 | if (!fromDisk) { | ||
339 | const plugin = await PluginModel.loadByNpmName(toUpdate) | ||
340 | version = plugin.latestVersion | ||
341 | } | ||
342 | |||
336 | // Unregister old hooks | 343 | // Unregister old hooks |
337 | await this.unregister(npmName) | 344 | await this.unregister(npmName) |
338 | 345 | ||
diff --git a/server/lib/plugins/yarn.ts b/server/lib/plugins/yarn.ts index e40351b6e..3f45681d3 100644 --- a/server/lib/plugins/yarn.ts +++ b/server/lib/plugins/yarn.ts | |||
@@ -1,14 +1,17 @@ | |||
1 | import { outputJSON, pathExists } from 'fs-extra' | ||
2 | import { join } from 'path' | ||
1 | import { execShell } from '../../helpers/core-utils' | 3 | import { execShell } from '../../helpers/core-utils' |
2 | import { logger } from '../../helpers/logger' | ||
3 | import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 4 | import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
5 | import { logger } from '../../helpers/logger' | ||
4 | import { CONFIG } from '../../initializers/config' | 6 | import { CONFIG } from '../../initializers/config' |
5 | import { outputJSON, pathExists } from 'fs-extra' | 7 | import { getLatestPluginVersion } from './plugin-index' |
6 | import { join } from 'path' | ||
7 | 8 | ||
8 | async function installNpmPlugin (npmName: string, version?: string) { | 9 | async function installNpmPlugin (npmName: string, versionArg?: string) { |
9 | // Security check | 10 | // Security check |
10 | checkNpmPluginNameOrThrow(npmName) | 11 | checkNpmPluginNameOrThrow(npmName) |
11 | if (version) checkPluginVersionOrThrow(version) | 12 | if (versionArg) checkPluginVersionOrThrow(versionArg) |
13 | |||
14 | const version = versionArg || await getLatestPluginVersion(npmName) | ||
12 | 15 | ||
13 | let toInstall = npmName | 16 | let toInstall = npmName |
14 | if (version) toInstall += `@${version}` | 17 | if (version) toInstall += `@${version}` |