aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-16 14:52:24 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commite0ce715a1ded6e84c877004dae3e354c8716fb06 (patch)
treec2a48af098e27fea2c2c6bb47b2daa68103c1a0e /server/lib
parent89c344dba4ae2fca39cf636c3c6f09f31a339493 (diff)
downloadPeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.tar.gz
PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.tar.zst
PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.zip
Check latest plugins version
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/plugins/plugin-index.ts15
-rw-r--r--server/lib/schedulers/plugins-check-scheduler.ts30
2 files changed, 29 insertions, 16 deletions
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts
index 4a8a90ec8..63cd47e63 100644
--- a/server/lib/plugins/plugin-index.ts
+++ b/server/lib/plugins/plugin-index.ts
@@ -27,13 +27,18 @@ async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList)
27 27
28 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins' 28 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins'
29 29
30 const { body } = await doRequest({ uri, qs, json: true }) 30 try {
31 const { body } = await doRequest({ uri, qs, json: true })
31 32
32 logger.debug('Got result from PeerTube index.', { body }) 33 logger.debug('Got result from PeerTube index.', { body })
33 34
34 await addInstanceInformation(body) 35 await addInstanceInformation(body)
35 36
36 return body as ResultList<PeerTubePluginIndex> 37 return body as ResultList<PeerTubePluginIndex>
38 } catch (err) {
39 logger.error('Cannot list available plugins from index %s.', uri, { err })
40 return undefined
41 }
37} 42}
38 43
39async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) { 44async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) {
@@ -53,7 +58,7 @@ async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePlu
53 58
54 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version' 59 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version'
55 60
56 const { body } = await doRequest({ uri, body: bodyRequest }) 61 const { body } = await doRequest({ uri, body: bodyRequest, json: true, method: 'POST' })
57 62
58 return body 63 return body
59} 64}
diff --git a/server/lib/schedulers/plugins-check-scheduler.ts b/server/lib/schedulers/plugins-check-scheduler.ts
index 9c60dbcd4..8dfdd5177 100644
--- a/server/lib/schedulers/plugins-check-scheduler.ts
+++ b/server/lib/schedulers/plugins-check-scheduler.ts
@@ -1,6 +1,5 @@
1import { logger } from '../../helpers/logger' 1import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler' 2import { AbstractScheduler } from './abstract-scheduler'
3import { retryTransactionWrapper } from '../../helpers/database-utils'
4import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' 3import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
5import { CONFIG } from '../../initializers/config' 4import { CONFIG } from '../../initializers/config'
6import { PluginModel } from '../../models/server/plugin' 5import { PluginModel } from '../../models/server/plugin'
@@ -19,13 +18,13 @@ export class PluginsCheckScheduler extends AbstractScheduler {
19 } 18 }
20 19
21 protected async internalExecute () { 20 protected async internalExecute () {
22 return retryTransactionWrapper(this.checkLatestPluginsVersion.bind(this)) 21 return this.checkLatestPluginsVersion()
23 } 22 }
24 23
25 private async checkLatestPluginsVersion () { 24 private async checkLatestPluginsVersion () {
26 if (CONFIG.PLUGINS.INDEX.ENABLED === false) return 25 if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
27 26
28 logger.info('Checkin latest plugins version.') 27 logger.info('Checking latest plugins version.')
29 28
30 const plugins = await PluginModel.listInstalled() 29 const plugins = await PluginModel.listInstalled()
31 30
@@ -39,19 +38,28 @@ export class PluginsCheckScheduler extends AbstractScheduler {
39 } 38 }
40 39
41 const npmNames = Object.keys(pluginIndex) 40 const npmNames = Object.keys(pluginIndex)
42 const results = await getLatestPluginsVersion(npmNames)
43 41
44 for (const result of results) { 42 try {
45 const plugin = pluginIndex[result.npmName] 43 const results = await getLatestPluginsVersion(npmNames)
46 if (!result.latestVersion) continue
47 44
48 if (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0) { 45 for (const result of results) {
49 plugin.latestVersion = result.latestVersion 46 const plugin = pluginIndex[ result.npmName ]
50 await plugin.save() 47 if (!result.latestVersion) continue
48
49 if (
50 !plugin.latestVersion ||
51 (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0)
52 ) {
53 plugin.latestVersion = result.latestVersion
54 await plugin.save()
55
56 logger.info('Plugin %s has a new latest version %s.', PluginModel.buildNpmName(plugin.name, plugin.type), plugin.latestVersion)
57 }
51 } 58 }
59 } catch (err) {
60 logger.error('Cannot get latest plugins version.', { npmNames, err })
52 } 61 }
53 } 62 }
54
55 } 63 }
56 64
57 static get Instance () { 65 static get Instance () {