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'
13 import { PEERTUBE_VERSION } from '../../initializers/constants'
15 async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) {
16 const { start = 0, count = 20, search, sort = 'npmName', pluginType } = options
18 const qs: PeertubePluginIndexList = {
24 currentPeerTubeEngine: options.currentPeerTubeEngine || PEERTUBE_VERSION
27 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>
38 logger.error('Cannot list available plugins from index %s.', uri, { err })
43 async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) {
44 for (const d of result.data) {
45 d.installed = PluginManager.Instance.isRegistered(d.npmName)
46 d.name = PluginModel.normalizePluginName(d.npmName)
52 async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePluginLatestVersionResponse> {
53 const bodyRequest: PeertubePluginLatestVersionRequest = {
55 currentPeerTubeEngine: PEERTUBE_VERSION
58 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version'
60 const { body } = await doRequest({ uri, body: bodyRequest, json: true, method: 'POST' })
66 listAvailablePluginsFromIndex,
67 getLatestPluginsVersion