]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/plugins.ts
Add public settings endpoint
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / plugins.ts
CommitLineData
09071200 1import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
8d2be0ed 2import { PluginType } from '../../models/plugins/plugin.type'
09071200
C
3import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model'
4import { readJSON, writeJSON } from 'fs-extra'
5import { ServerInfo } from './servers'
6import { root } from '../miscs/miscs'
7import { join } from 'path'
8d2be0ed
C
8
9function listPlugins (parameters: {
10 url: string,
11 accessToken: string,
12 start?: number,
13 count?: number,
14 sort?: string,
09071200
C
15 pluginType?: PluginType,
16 uninstalled?: boolean,
8d2be0ed
C
17 expectedStatus?: number
18}) {
09071200 19 const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters
8d2be0ed
C
20 const path = '/api/v1/plugins'
21
22 return makeGetRequest({
23 url,
24 path,
25 token: accessToken,
26 query: {
27 start,
28 count,
29 sort,
09071200
C
30 pluginType,
31 uninstalled
8d2be0ed
C
32 },
33 statusCodeExpected: expectedStatus
34 })
35}
36
09071200
C
37function listAvailablePlugins (parameters: {
38 url: string,
39 accessToken: string,
40 start?: number,
41 count?: number,
42 sort?: string,
43 pluginType?: PluginType,
44 currentPeerTubeEngine?: string,
45 search?: string
46 expectedStatus?: number
47}) {
48 const { url, accessToken, start, count, sort, pluginType, search, currentPeerTubeEngine, expectedStatus = 200 } = parameters
49 const path = '/api/v1/plugins/available'
50
51 const query: PeertubePluginIndexList = {
52 start,
53 count,
54 sort,
55 pluginType,
56 currentPeerTubeEngine,
57 search
58 }
59
60 return makeGetRequest({
61 url,
62 path,
63 token: accessToken,
64 query,
65 statusCodeExpected: expectedStatus
66 })
67}
68
8d2be0ed
C
69function getPlugin (parameters: {
70 url: string,
71 accessToken: string,
72 npmName: string,
73 expectedStatus?: number
74}) {
75 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
76 const path = '/api/v1/plugins/' + npmName
77
78 return makeGetRequest({
79 url,
80 path,
81 token: accessToken,
82 statusCodeExpected: expectedStatus
83 })
84}
85
09071200 86function updatePluginSettings (parameters: {
8d2be0ed
C
87 url: string,
88 accessToken: string,
89 npmName: string,
09071200 90 settings: any,
8d2be0ed
C
91 expectedStatus?: number
92}) {
09071200 93 const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters
8d2be0ed
C
94 const path = '/api/v1/plugins/' + npmName + '/settings'
95
09071200 96 return makePutBodyRequest({
8d2be0ed
C
97 url,
98 path,
99 token: accessToken,
09071200 100 fields: { settings },
8d2be0ed
C
101 statusCodeExpected: expectedStatus
102 })
103}
104
105function getPluginRegisteredSettings (parameters: {
106 url: string,
107 accessToken: string,
108 npmName: string,
109 expectedStatus?: number
110}) {
111 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
112 const path = '/api/v1/plugins/' + npmName + '/registered-settings'
113
114 return makeGetRequest({
115 url,
116 path,
117 token: accessToken,
118 statusCodeExpected: expectedStatus
119 })
120}
121
ba211e73
C
122function getPublicSettings (parameters: {
123 url: string,
124 npmName: string,
125 expectedStatus?: number
126}) {
127 const { url, npmName, expectedStatus = 200 } = parameters
128 const path = '/api/v1/plugins/' + npmName + '/public-settings'
129
130 return makeGetRequest({
131 url,
132 path,
133 statusCodeExpected: expectedStatus
134 })
135}
136
8d2be0ed
C
137function installPlugin (parameters: {
138 url: string,
139 accessToken: string,
140 path?: string,
141 npmName?: string
142 expectedStatus?: number
143}) {
b5f919ac 144 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
8d2be0ed
C
145 const apiPath = '/api/v1/plugins/install'
146
147 return makePostBodyRequest({
148 url,
149 path: apiPath,
150 token: accessToken,
151 fields: { npmName, path },
152 statusCodeExpected: expectedStatus
153 })
154}
155
b5f919ac
C
156function updatePlugin (parameters: {
157 url: string,
158 accessToken: string,
159 path?: string,
160 npmName?: string
161 expectedStatus?: number
162}) {
163 const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
164 const apiPath = '/api/v1/plugins/update'
165
166 return makePostBodyRequest({
167 url,
168 path: apiPath,
169 token: accessToken,
170 fields: { npmName, path },
171 statusCodeExpected: expectedStatus
172 })
173}
174
8d2be0ed
C
175function uninstallPlugin (parameters: {
176 url: string,
177 accessToken: string,
178 npmName: string
179 expectedStatus?: number
180}) {
181 const { url, accessToken, npmName, expectedStatus = 204 } = parameters
182 const apiPath = '/api/v1/plugins/uninstall'
183
184 return makePostBodyRequest({
185 url,
186 path: apiPath,
187 token: accessToken,
188 fields: { npmName },
189 statusCodeExpected: expectedStatus
190 })
191}
192
09071200
C
193function getPluginsCSS (url: string) {
194 const path = '/plugins/global.css'
195
196 return makeGetRequest({
197 url,
198 path,
199 statusCodeExpected: 200
200 })
201}
202
203function getPackageJSONPath (server: ServerInfo, npmName: string) {
204 return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json')
205}
206
207function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {
208 const path = getPackageJSONPath(server, npmName)
209
210 return writeJSON(path, json)
211}
212
213function getPluginPackageJSON (server: ServerInfo, npmName: string) {
214 const path = getPackageJSONPath(server, npmName)
215
216 return readJSON(path)
217}
218
89cd1275
C
219function getPluginTestPath (suffix = '') {
220 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
221}
222
8d2be0ed
C
223export {
224 listPlugins,
09071200 225 listAvailablePlugins,
8d2be0ed 226 installPlugin,
09071200 227 getPluginsCSS,
b5f919ac 228 updatePlugin,
8d2be0ed
C
229 getPlugin,
230 uninstallPlugin,
09071200
C
231 updatePluginSettings,
232 getPluginRegisteredSettings,
233 getPackageJSONPath,
234 updatePluginPackageJSON,
89cd1275 235 getPluginPackageJSON,
ba211e73
C
236 getPluginTestPath,
237 getPublicSettings
8d2be0ed 238}