Check latest plugins version
This commit is contained in:
parent
89c344dba4
commit
e0ce715a1d
|
@ -113,6 +113,7 @@ import { RemoveOldHistoryScheduler } from './server/lib/schedulers/remove-old-hi
|
||||||
import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto'
|
import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto'
|
||||||
import { PeerTubeSocket } from './server/lib/peertube-socket'
|
import { PeerTubeSocket } from './server/lib/peertube-socket'
|
||||||
import { updateStreamingPlaylistsInfohashesIfNeeded } from './server/lib/hls'
|
import { updateStreamingPlaylistsInfohashesIfNeeded } from './server/lib/hls'
|
||||||
|
import { PluginsCheckScheduler } from './server/lib/schedulers/plugins-check-scheduler'
|
||||||
|
|
||||||
// ----------- Command line -----------
|
// ----------- Command line -----------
|
||||||
|
|
||||||
|
@ -250,6 +251,7 @@ async function startApplication () {
|
||||||
VideosRedundancyScheduler.Instance.enable()
|
VideosRedundancyScheduler.Instance.enable()
|
||||||
RemoveOldHistoryScheduler.Instance.enable()
|
RemoveOldHistoryScheduler.Instance.enable()
|
||||||
RemoveOldViewsScheduler.Instance.enable()
|
RemoveOldViewsScheduler.Instance.enable()
|
||||||
|
PluginsCheckScheduler.Instance.enable()
|
||||||
|
|
||||||
// Redis initialization
|
// Redis initialization
|
||||||
Redis.Instance.init()
|
Redis.Instance.init()
|
||||||
|
|
|
@ -180,5 +180,11 @@ async function listAvailablePlugins (req: express.Request, res: express.Response
|
||||||
|
|
||||||
const resultList = await listAvailablePluginsFromIndex(query)
|
const resultList = await listAvailablePluginsFromIndex(query)
|
||||||
|
|
||||||
|
if (!resultList) {
|
||||||
|
return res.status(503)
|
||||||
|
.json({ error: 'Plugin index unavailable. Please retry later' })
|
||||||
|
.end()
|
||||||
|
}
|
||||||
|
|
||||||
return res.json(resultList)
|
return res.json(resultList)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import { createWriteStream, remove } from 'fs-extra'
|
import { createWriteStream, remove } from 'fs-extra'
|
||||||
import * as request from 'request'
|
import * as request from 'request'
|
||||||
import { ACTIVITY_PUB } from '../initializers/constants'
|
import { ACTIVITY_PUB, WEBSERVER } from '../initializers/constants'
|
||||||
import { processImage } from './image-utils'
|
import { processImage } from './image-utils'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { CONFIG } from '../initializers/config'
|
import { CONFIG } from '../initializers/config'
|
||||||
|
|
||||||
|
const packageJSON = require('../../../package.json')
|
||||||
|
|
||||||
function doRequest <T> (
|
function doRequest <T> (
|
||||||
requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean },
|
requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean },
|
||||||
bodyKBLimit = 1000 // 1MB
|
bodyKBLimit = 1000 // 1MB
|
||||||
): Bluebird<{ response: request.RequestResponse, body: T }> {
|
): Bluebird<{ response: request.RequestResponse, body: T }> {
|
||||||
|
if (!(requestOptions.headers)) requestOptions.headers = {}
|
||||||
|
requestOptions.headers['User-Agent'] = getUserAgent()
|
||||||
|
|
||||||
if (requestOptions.activityPub === true) {
|
if (requestOptions.activityPub === true) {
|
||||||
if (!Array.isArray(requestOptions.headers)) requestOptions.headers = {}
|
|
||||||
requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER
|
requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +31,9 @@ function doRequestAndSaveToFile (
|
||||||
destPath: string,
|
destPath: string,
|
||||||
bodyKBLimit = 10000 // 10MB
|
bodyKBLimit = 10000 // 10MB
|
||||||
) {
|
) {
|
||||||
|
if (!requestOptions.headers) requestOptions.headers = {}
|
||||||
|
requestOptions.headers['User-Agent'] = getUserAgent()
|
||||||
|
|
||||||
return new Bluebird<void>((res, rej) => {
|
return new Bluebird<void>((res, rej) => {
|
||||||
const file = createWriteStream(destPath)
|
const file = createWriteStream(destPath)
|
||||||
file.on('finish', () => res())
|
file.on('finish', () => res())
|
||||||
|
@ -60,6 +67,10 @@ async function downloadImage (url: string, destDir: string, destName: string, si
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUserAgent () {
|
||||||
|
return `PeerTube/${packageJSON.version} (+${WEBSERVER.URL})`
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -618,6 +618,7 @@ if (isTestInstance() === true) {
|
||||||
SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
|
SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
|
||||||
SCHEDULER_INTERVALS_MS.removeOldViews = 5000
|
SCHEDULER_INTERVALS_MS.removeOldViews = 5000
|
||||||
SCHEDULER_INTERVALS_MS.updateVideos = 5000
|
SCHEDULER_INTERVALS_MS.updateVideos = 5000
|
||||||
|
SCHEDULER_INTERVALS_MS.checkPlugins = 10000
|
||||||
REPEAT_JOBS[ 'videos-views' ] = { every: 5000 }
|
REPEAT_JOBS[ 'videos-views' ] = { every: 5000 }
|
||||||
|
|
||||||
REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
|
REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
|
||||||
|
|
|
@ -27,13 +27,18 @@ async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList)
|
||||||
|
|
||||||
const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins'
|
const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins'
|
||||||
|
|
||||||
const { body } = await doRequest({ uri, qs, json: true })
|
try {
|
||||||
|
const { body } = await doRequest({ uri, qs, json: true })
|
||||||
|
|
||||||
logger.debug('Got result from PeerTube index.', { body })
|
logger.debug('Got result from PeerTube index.', { body })
|
||||||
|
|
||||||
await addInstanceInformation(body)
|
await addInstanceInformation(body)
|
||||||
|
|
||||||
return body as ResultList<PeerTubePluginIndex>
|
return body as ResultList<PeerTubePluginIndex>
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Cannot list available plugins from index %s.', uri, { err })
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) {
|
async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) {
|
||||||
|
@ -53,7 +58,7 @@ async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePlu
|
||||||
|
|
||||||
const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version'
|
const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version'
|
||||||
|
|
||||||
const { body } = await doRequest({ uri, body: bodyRequest })
|
const { body } = await doRequest({ uri, body: bodyRequest, json: true, method: 'POST' })
|
||||||
|
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { AbstractScheduler } from './abstract-scheduler'
|
import { AbstractScheduler } from './abstract-scheduler'
|
||||||
import { retryTransactionWrapper } from '../../helpers/database-utils'
|
|
||||||
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
||||||
import { CONFIG } from '../../initializers/config'
|
import { CONFIG } from '../../initializers/config'
|
||||||
import { PluginModel } from '../../models/server/plugin'
|
import { PluginModel } from '../../models/server/plugin'
|
||||||
|
@ -19,13 +18,13 @@ export class PluginsCheckScheduler extends AbstractScheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async internalExecute () {
|
protected async internalExecute () {
|
||||||
return retryTransactionWrapper(this.checkLatestPluginsVersion.bind(this))
|
return this.checkLatestPluginsVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkLatestPluginsVersion () {
|
private async checkLatestPluginsVersion () {
|
||||||
if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
|
if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
|
||||||
|
|
||||||
logger.info('Checkin latest plugins version.')
|
logger.info('Checking latest plugins version.')
|
||||||
|
|
||||||
const plugins = await PluginModel.listInstalled()
|
const plugins = await PluginModel.listInstalled()
|
||||||
|
|
||||||
|
@ -39,19 +38,28 @@ export class PluginsCheckScheduler extends AbstractScheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
const npmNames = Object.keys(pluginIndex)
|
const npmNames = Object.keys(pluginIndex)
|
||||||
const results = await getLatestPluginsVersion(npmNames)
|
|
||||||
|
|
||||||
for (const result of results) {
|
try {
|
||||||
const plugin = pluginIndex[result.npmName]
|
const results = await getLatestPluginsVersion(npmNames)
|
||||||
if (!result.latestVersion) continue
|
|
||||||
|
|
||||||
if (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0) {
|
for (const result of results) {
|
||||||
plugin.latestVersion = result.latestVersion
|
const plugin = pluginIndex[ result.npmName ]
|
||||||
await plugin.save()
|
if (!result.latestVersion) continue
|
||||||
|
|
||||||
|
if (
|
||||||
|
!plugin.latestVersion ||
|
||||||
|
(plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0)
|
||||||
|
) {
|
||||||
|
plugin.latestVersion = result.latestVersion
|
||||||
|
await plugin.save()
|
||||||
|
|
||||||
|
logger.info('Plugin %s has a new latest version %s.', PluginModel.buildNpmName(plugin.name, plugin.type), plugin.latestVersion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Cannot get latest plugins version.', { npmNames, err })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static get Instance () {
|
static get Instance () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user