1 import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2 import { PluginType } from '../../models/plugins/plugin.type'
3 import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model'
4 import { readJSON, writeJSON } from 'fs-extra'
5 import { ServerInfo } from './servers'
6 import { root } from '../miscs/miscs'
7 import { join } from 'path'
9 function listPlugins (parameters: {
15 pluginType?: PluginType,
16 uninstalled?: boolean,
17 expectedStatus?: number
19 const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters
20 const path = '/api/v1/plugins'
22 return makeGetRequest({
33 statusCodeExpected: expectedStatus
37 function listAvailablePlugins (parameters: {
43 pluginType?: PluginType,
44 currentPeerTubeEngine?: string,
46 expectedStatus?: number
48 const { url, accessToken, start, count, sort, pluginType, search, currentPeerTubeEngine, expectedStatus = 200 } = parameters
49 const path = '/api/v1/plugins/available'
51 const query: PeertubePluginIndexList = {
56 currentPeerTubeEngine,
60 return makeGetRequest({
65 statusCodeExpected: expectedStatus
69 function getPlugin (parameters: {
73 expectedStatus?: number
75 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
76 const path = '/api/v1/plugins/' + npmName
78 return makeGetRequest({
82 statusCodeExpected: expectedStatus
86 function updatePluginSettings (parameters: {
91 expectedStatus?: number
93 const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters
94 const path = '/api/v1/plugins/' + npmName + '/settings'
96 return makePutBodyRequest({
100 fields: { settings },
101 statusCodeExpected: expectedStatus
105 function getPluginRegisteredSettings (parameters: {
109 expectedStatus?: number
111 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
112 const path = '/api/v1/plugins/' + npmName + '/registered-settings'
114 return makeGetRequest({
118 statusCodeExpected: expectedStatus
122 function installPlugin (parameters: {
127 expectedStatus?: number
129 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
130 const apiPath = '/api/v1/plugins/install'
132 return makePostBodyRequest({
136 fields: { npmName, path },
137 statusCodeExpected: expectedStatus
141 function updatePlugin (parameters: {
146 expectedStatus?: number
148 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
149 const apiPath = '/api/v1/plugins/update'
151 return makePostBodyRequest({
155 fields: { npmName, path },
156 statusCodeExpected: expectedStatus
160 function uninstallPlugin (parameters: {
164 expectedStatus?: number
166 const { url, accessToken, npmName, expectedStatus = 204 } = parameters
167 const apiPath = '/api/v1/plugins/uninstall'
169 return makePostBodyRequest({
174 statusCodeExpected: expectedStatus
178 function getPluginsCSS (url: string) {
179 const path = '/plugins/global.css'
181 return makeGetRequest({
184 statusCodeExpected: 200
188 function getPackageJSONPath (server: ServerInfo, npmName: string) {
189 return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json')
192 function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {
193 const path = getPackageJSONPath(server, npmName)
195 return writeJSON(path, json)
198 function getPluginPackageJSON (server: ServerInfo, npmName: string) {
199 const path = getPackageJSONPath(server, npmName)
201 return readJSON(path)
204 function getPluginTestPath (suffix = '') {
205 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
210 listAvailablePlugins,
216 updatePluginSettings,
217 getPluginRegisteredSettings,
219 updatePluginPackageJSON,
220 getPluginPackageJSON,