]>
Commit | Line | Data |
---|---|---|
09071200 | 1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
8d2be0ed | 2 | import { PluginType } from '../../models/plugins/plugin.type' |
09071200 C |
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' | |
8d2be0ed C |
8 | |
9 | function listPlugins (parameters: { | |
a1587156 C |
10 | url: string |
11 | accessToken: string | |
12 | start?: number | |
13 | count?: number | |
14 | sort?: string | |
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 | 37 | function listAvailablePlugins (parameters: { |
a1587156 C |
38 | url: string |
39 | accessToken: string | |
40 | start?: number | |
41 | count?: number | |
42 | sort?: string | |
43 | pluginType?: PluginType | |
44 | currentPeerTubeEngine?: string | |
09071200 C |
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 | 69 | function getPlugin (parameters: { |
a1587156 C |
70 | url: string |
71 | accessToken: string | |
72 | npmName: string | |
8d2be0ed C |
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 | 86 | function updatePluginSettings (parameters: { |
a1587156 C |
87 | url: string |
88 | accessToken: string | |
89 | npmName: string | |
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 | ||
105 | function getPluginRegisteredSettings (parameters: { | |
a1587156 C |
106 | url: string |
107 | accessToken: string | |
108 | npmName: string | |
8d2be0ed C |
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 | 122 | function getPublicSettings (parameters: { |
a1587156 C |
123 | url: string |
124 | npmName: string | |
ba211e73 C |
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 | ||
d75db01f | 137 | function getPluginTranslations (parameters: { |
a1587156 C |
138 | url: string |
139 | locale: string | |
d75db01f C |
140 | expectedStatus?: number |
141 | }) { | |
142 | const { url, locale, expectedStatus = 200 } = parameters | |
143 | const path = '/plugins/translations/' + locale + '.json' | |
144 | ||
145 | return makeGetRequest({ | |
146 | url, | |
147 | path, | |
148 | statusCodeExpected: expectedStatus | |
149 | }) | |
150 | } | |
151 | ||
8d2be0ed | 152 | function installPlugin (parameters: { |
a1587156 C |
153 | url: string |
154 | accessToken: string | |
155 | path?: string | |
8d2be0ed C |
156 | npmName?: string |
157 | expectedStatus?: number | |
158 | }) { | |
b5f919ac | 159 | const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters |
8d2be0ed C |
160 | const apiPath = '/api/v1/plugins/install' |
161 | ||
162 | return makePostBodyRequest({ | |
163 | url, | |
164 | path: apiPath, | |
165 | token: accessToken, | |
166 | fields: { npmName, path }, | |
167 | statusCodeExpected: expectedStatus | |
168 | }) | |
169 | } | |
170 | ||
b5f919ac | 171 | function updatePlugin (parameters: { |
a1587156 C |
172 | url: string |
173 | accessToken: string | |
174 | path?: string | |
b5f919ac C |
175 | npmName?: string |
176 | expectedStatus?: number | |
177 | }) { | |
178 | const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters | |
179 | const apiPath = '/api/v1/plugins/update' | |
180 | ||
181 | return makePostBodyRequest({ | |
182 | url, | |
183 | path: apiPath, | |
184 | token: accessToken, | |
185 | fields: { npmName, path }, | |
186 | statusCodeExpected: expectedStatus | |
187 | }) | |
188 | } | |
189 | ||
8d2be0ed | 190 | function uninstallPlugin (parameters: { |
a1587156 C |
191 | url: string |
192 | accessToken: string | |
8d2be0ed C |
193 | npmName: string |
194 | expectedStatus?: number | |
195 | }) { | |
196 | const { url, accessToken, npmName, expectedStatus = 204 } = parameters | |
197 | const apiPath = '/api/v1/plugins/uninstall' | |
198 | ||
199 | return makePostBodyRequest({ | |
200 | url, | |
201 | path: apiPath, | |
202 | token: accessToken, | |
203 | fields: { npmName }, | |
204 | statusCodeExpected: expectedStatus | |
205 | }) | |
206 | } | |
207 | ||
09071200 C |
208 | function getPluginsCSS (url: string) { |
209 | const path = '/plugins/global.css' | |
210 | ||
211 | return makeGetRequest({ | |
212 | url, | |
213 | path, | |
214 | statusCodeExpected: 200 | |
215 | }) | |
216 | } | |
217 | ||
218 | function getPackageJSONPath (server: ServerInfo, npmName: string) { | |
219 | return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json') | |
220 | } | |
221 | ||
222 | function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) { | |
223 | const path = getPackageJSONPath(server, npmName) | |
224 | ||
225 | return writeJSON(path, json) | |
226 | } | |
227 | ||
228 | function getPluginPackageJSON (server: ServerInfo, npmName: string) { | |
229 | const path = getPackageJSONPath(server, npmName) | |
230 | ||
231 | return readJSON(path) | |
232 | } | |
233 | ||
89cd1275 C |
234 | function getPluginTestPath (suffix = '') { |
235 | return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) | |
236 | } | |
237 | ||
8d2be0ed C |
238 | export { |
239 | listPlugins, | |
09071200 | 240 | listAvailablePlugins, |
8d2be0ed | 241 | installPlugin, |
d75db01f | 242 | getPluginTranslations, |
09071200 | 243 | getPluginsCSS, |
b5f919ac | 244 | updatePlugin, |
8d2be0ed C |
245 | getPlugin, |
246 | uninstallPlugin, | |
09071200 C |
247 | updatePluginSettings, |
248 | getPluginRegisteredSettings, | |
249 | getPackageJSONPath, | |
250 | updatePluginPackageJSON, | |
89cd1275 | 251 | getPluginPackageJSON, |
ba211e73 C |
252 | getPluginTestPath, |
253 | getPublicSettings | |
8d2be0ed | 254 | } |