1 import { doRequest } from '../../helpers/requests'
2 import { CONFIG } from '../../initializers/config'
4 PeertubePluginLatestVersionRequest,
5 PeertubePluginLatestVersionResponse
6 } from '../../../shared/models/plugins/peertube-plugin-latest-version.model'
7 import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model'
8 import { ResultList } from '../../../shared/models'
9 import { PeerTubePluginIndex } from '../../../shared/models/plugins/peertube-plugin-index.model'
10 import { PluginModel } from '../../models/server/plugin'
11 import { PluginManager } from './plugin-manager'
12 import { logger } from '../../helpers/logger'
14 const packageJSON = require('../../../../package.json')
16 async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) {
17 const { start = 0, count = 20, search, sort = 'npmName', pluginType } = options
19 const qs: PeertubePluginIndexList = {
25 currentPeerTubeEngine: packageJSON.version
28 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins'
30 const { body } = await doRequest({ uri, qs, json: true })
32 logger.debug('Got result from PeerTube index.', { body })
34 await addInstanceInformation(body)
36 return body as ResultList<PeerTubePluginIndex>
39 async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) {
40 for (const d of result.data) {
41 d.installed = PluginManager.Instance.isRegistered(d.npmName)
42 d.name = PluginModel.normalizePluginName(d.npmName)
48 async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePluginLatestVersionResponse> {
49 const bodyRequest: PeertubePluginLatestVersionRequest = {
51 currentPeerTubeEngine: packageJSON.version
54 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version'
56 const { body } = await doRequest({ uri, body: bodyRequest })
62 listAvailablePluginsFromIndex,
63 getLatestPluginsVersion