import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto'
import { PeerTubeSocket } from './server/lib/peertube-socket'
import { updateStreamingPlaylistsInfohashesIfNeeded } from './server/lib/hls'
+import { PluginsCheckScheduler } from './server/lib/schedulers/plugins-check-scheduler'
// ----------- Command line -----------
VideosRedundancyScheduler.Instance.enable()
RemoveOldHistoryScheduler.Instance.enable()
RemoveOldViewsScheduler.Instance.enable()
+ PluginsCheckScheduler.Instance.enable()
// Redis initialization
Redis.Instance.init()
const resultList = await listAvailablePluginsFromIndex(query)
+ if (!resultList) {
+ return res.status(503)
+ .json({ error: 'Plugin index unavailable. Please retry later' })
+ .end()
+ }
+
return res.json(resultList)
}
import * as Bluebird from 'bluebird'
import { createWriteStream, remove } from 'fs-extra'
import * as request from 'request'
-import { ACTIVITY_PUB } from '../initializers/constants'
+import { ACTIVITY_PUB, WEBSERVER } from '../initializers/constants'
import { processImage } from './image-utils'
import { join } from 'path'
import { logger } from './logger'
import { CONFIG } from '../initializers/config'
+const packageJSON = require('../../../package.json')
+
function doRequest <T> (
requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean },
bodyKBLimit = 1000 // 1MB
): Bluebird<{ response: request.RequestResponse, body: T }> {
+ if (!(requestOptions.headers)) requestOptions.headers = {}
+ requestOptions.headers['User-Agent'] = getUserAgent()
+
if (requestOptions.activityPub === true) {
- if (!Array.isArray(requestOptions.headers)) requestOptions.headers = {}
requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER
}
destPath: string,
bodyKBLimit = 10000 // 10MB
) {
+ if (!requestOptions.headers) requestOptions.headers = {}
+ requestOptions.headers['User-Agent'] = getUserAgent()
+
return new Bluebird<void>((res, rej) => {
const file = createWriteStream(destPath)
file.on('finish', () => res())
}
}
+function getUserAgent () {
+ return `PeerTube/${packageJSON.version} (+${WEBSERVER.URL})`
+}
+
// ---------------------------------------------------------------------------
export {
SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
SCHEDULER_INTERVALS_MS.removeOldViews = 5000
SCHEDULER_INTERVALS_MS.updateVideos = 5000
+ SCHEDULER_INTERVALS_MS.checkPlugins = 10000
REPEAT_JOBS[ 'videos-views' ] = { every: 5000 }
REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
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>) {
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
}
import { logger } from '../../helpers/logger'
import { AbstractScheduler } from './abstract-scheduler'
-import { retryTransactionWrapper } from '../../helpers/database-utils'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
import { CONFIG } from '../../initializers/config'
import { PluginModel } from '../../models/server/plugin'
}
protected async internalExecute () {
- return retryTransactionWrapper(this.checkLatestPluginsVersion.bind(this))
+ return this.checkLatestPluginsVersion()
}
private async checkLatestPluginsVersion () {
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 npmNames = Object.keys(pluginIndex)
- const results = await getLatestPluginsVersion(npmNames)
- for (const result of results) {
- const plugin = pluginIndex[result.npmName]
- if (!result.latestVersion) continue
+ try {
+ const results = await getLatestPluginsVersion(npmNames)
- if (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0) {
- plugin.latestVersion = result.latestVersion
- await plugin.save()
+ for (const result of results) {
+ const plugin = pluginIndex[ result.npmName ]
+ 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 () {