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 getPublicSettings (parameters: {
125 expectedStatus?: number
127 const { url, npmName, expectedStatus = 200 } = parameters
128 const path = '/api/v1/plugins/' + npmName + '/public-settings'
130 return makeGetRequest({
133 statusCodeExpected: expectedStatus
137 function installPlugin (parameters: {
142 expectedStatus?: number
144 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
145 const apiPath = '/api/v1/plugins/install'
147 return makePostBodyRequest({
151 fields: { npmName, path },
152 statusCodeExpected: expectedStatus
156 function updatePlugin (parameters: {
161 expectedStatus?: number
163 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
164 const apiPath = '/api/v1/plugins/update'
166 return makePostBodyRequest({
170 fields: { npmName, path },
171 statusCodeExpected: expectedStatus
175 function uninstallPlugin (parameters: {
179 expectedStatus?: number
181 const { url, accessToken, npmName, expectedStatus = 204 } = parameters
182 const apiPath = '/api/v1/plugins/uninstall'
184 return makePostBodyRequest({
189 statusCodeExpected: expectedStatus
193 function getPluginsCSS (url: string) {
194 const path = '/plugins/global.css'
196 return makeGetRequest({
199 statusCodeExpected: 200
203 function getPackageJSONPath (server: ServerInfo, npmName: string) {
204 return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json')
207 function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {
208 const path = getPackageJSONPath(server, npmName)
210 return writeJSON(path, json)
213 function getPluginPackageJSON (server: ServerInfo, npmName: string) {
214 const path = getPackageJSONPath(server, npmName)
216 return readJSON(path)
219 function getPluginTestPath (suffix = '') {
220 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
225 listAvailablePlugins,
231 updatePluginSettings,
232 getPluginRegisteredSettings,
234 updatePluginPackageJSON,
235 getPluginPackageJSON,