]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/plugins/plugin-index.ts
Add external login buttons
[github/Chocobozzz/PeerTube.git] / server / lib / plugins / plugin-index.ts
CommitLineData
6702a1b2
C
1import { doRequest } from '../../helpers/requests'
2import { CONFIG } from '../../initializers/config'
3import {
4 PeertubePluginLatestVersionRequest,
5 PeertubePluginLatestVersionResponse
6} from '../../../shared/models/plugins/peertube-plugin-latest-version.model'
7import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model'
8import { ResultList } from '../../../shared/models'
9import { PeerTubePluginIndex } from '../../../shared/models/plugins/peertube-plugin-index.model'
10import { PluginModel } from '../../models/server/plugin'
11import { PluginManager } from './plugin-manager'
12import { logger } from '../../helpers/logger'
66170ca8 13import { PEERTUBE_VERSION } from '../../initializers/constants'
6702a1b2
C
14
15async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) {
16 const { start = 0, count = 20, search, sort = 'npmName', pluginType } = options
17
18 const qs: PeertubePluginIndexList = {
19 start,
20 count,
21 sort,
22 pluginType,
23 search,
09071200 24 currentPeerTubeEngine: options.currentPeerTubeEngine || PEERTUBE_VERSION
6702a1b2
C
25 }
26
27 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins'
28
e0ce715a 29 try {
366caf8b 30 const { body } = await doRequest<any>({ uri, qs, json: true })
6702a1b2 31
e0ce715a 32 logger.debug('Got result from PeerTube index.', { body })
6702a1b2 33
a1587156 34 addInstanceInformation(body)
6702a1b2 35
e0ce715a
C
36 return body as ResultList<PeerTubePluginIndex>
37 } catch (err) {
38 logger.error('Cannot list available plugins from index %s.', uri, { err })
39 return undefined
40 }
6702a1b2
C
41}
42
a1587156 43function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) {
6702a1b2
C
44 for (const d of result.data) {
45 d.installed = PluginManager.Instance.isRegistered(d.npmName)
46 d.name = PluginModel.normalizePluginName(d.npmName)
47 }
48
49 return result
50}
51
52async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePluginLatestVersionResponse> {
53 const bodyRequest: PeertubePluginLatestVersionRequest = {
54 npmNames,
66170ca8 55 currentPeerTubeEngine: PEERTUBE_VERSION
6702a1b2
C
56 }
57
58 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version'
59
366caf8b 60 const { body } = await doRequest<any>({ uri, body: bodyRequest, json: true, method: 'POST' })
6702a1b2
C
61
62 return body
63}
64
65export {
66 listAvailablePluginsFromIndex,
67 getLatestPluginsVersion
68}