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 getPluginTranslations (parameters: {
140 expectedStatus?: number
142 const { url, locale, expectedStatus = 200 } = parameters
143 const path = '/plugins/translations/' + locale + '.json'
145 return makeGetRequest({
148 statusCodeExpected: expectedStatus
152 function installPlugin (parameters: {
157 expectedStatus?: number
159 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
160 const apiPath = '/api/v1/plugins/install'
162 return makePostBodyRequest({
166 fields: { npmName, path },
167 statusCodeExpected: expectedStatus
171 function updatePlugin (parameters: {
176 expectedStatus?: number
178 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
179 const apiPath = '/api/v1/plugins/update'
181 return makePostBodyRequest({
185 fields: { npmName, path },
186 statusCodeExpected: expectedStatus
190 function uninstallPlugin (parameters: {
194 expectedStatus?: number
196 const { url, accessToken, npmName, expectedStatus = 204 } = parameters
197 const apiPath = '/api/v1/plugins/uninstall'
199 return makePostBodyRequest({
204 statusCodeExpected: expectedStatus
208 function getPluginsCSS (url: string) {
209 const path = '/plugins/global.css'
211 return makeGetRequest({
214 statusCodeExpected: 200
218 function getPackageJSONPath (server: ServerInfo, npmName: string) {
219 return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json')
222 function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {
223 const path = getPackageJSONPath(server, npmName)
225 return writeJSON(path, json)
228 function getPluginPackageJSON (server: ServerInfo, npmName: string) {
229 const path = getPackageJSONPath(server, npmName)
231 return readJSON(path)
234 function getPluginTestPath (suffix = '') {
235 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
240 listAvailablePlugins,
242 getPluginTranslations,
247 updatePluginSettings,
248 getPluginRegisteredSettings,
250 updatePluginPackageJSON,
251 getPluginPackageJSON,