]>
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: { | |
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 |
37 | function 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 |
69 | function 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 | 86 | function 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 | ||
105 | function 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 | ||
122 | function installPlugin (parameters: { | |
123 | url: string, | |
124 | accessToken: string, | |
125 | path?: string, | |
126 | npmName?: string | |
127 | expectedStatus?: number | |
128 | }) { | |
b5f919ac | 129 | const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters |
8d2be0ed C |
130 | const apiPath = '/api/v1/plugins/install' |
131 | ||
132 | return makePostBodyRequest({ | |
133 | url, | |
134 | path: apiPath, | |
135 | token: accessToken, | |
136 | fields: { npmName, path }, | |
137 | statusCodeExpected: expectedStatus | |
138 | }) | |
139 | } | |
140 | ||
b5f919ac C |
141 | function updatePlugin (parameters: { |
142 | url: string, | |
143 | accessToken: string, | |
144 | path?: string, | |
145 | npmName?: string | |
146 | expectedStatus?: number | |
147 | }) { | |
148 | const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters | |
149 | const apiPath = '/api/v1/plugins/update' | |
150 | ||
151 | return makePostBodyRequest({ | |
152 | url, | |
153 | path: apiPath, | |
154 | token: accessToken, | |
155 | fields: { npmName, path }, | |
156 | statusCodeExpected: expectedStatus | |
157 | }) | |
158 | } | |
159 | ||
8d2be0ed C |
160 | function uninstallPlugin (parameters: { |
161 | url: string, | |
162 | accessToken: string, | |
163 | npmName: string | |
164 | expectedStatus?: number | |
165 | }) { | |
166 | const { url, accessToken, npmName, expectedStatus = 204 } = parameters | |
167 | const apiPath = '/api/v1/plugins/uninstall' | |
168 | ||
169 | return makePostBodyRequest({ | |
170 | url, | |
171 | path: apiPath, | |
172 | token: accessToken, | |
173 | fields: { npmName }, | |
174 | statusCodeExpected: expectedStatus | |
175 | }) | |
176 | } | |
177 | ||
09071200 C |
178 | function getPluginsCSS (url: string) { |
179 | const path = '/plugins/global.css' | |
180 | ||
181 | return makeGetRequest({ | |
182 | url, | |
183 | path, | |
184 | statusCodeExpected: 200 | |
185 | }) | |
186 | } | |
187 | ||
188 | function getPackageJSONPath (server: ServerInfo, npmName: string) { | |
189 | return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json') | |
190 | } | |
191 | ||
192 | function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) { | |
193 | const path = getPackageJSONPath(server, npmName) | |
194 | ||
195 | return writeJSON(path, json) | |
196 | } | |
197 | ||
198 | function getPluginPackageJSON (server: ServerInfo, npmName: string) { | |
199 | const path = getPackageJSONPath(server, npmName) | |
200 | ||
201 | return readJSON(path) | |
202 | } | |
203 | ||
89cd1275 C |
204 | function getPluginTestPath (suffix = '') { |
205 | return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) | |
206 | } | |
207 | ||
8d2be0ed C |
208 | export { |
209 | listPlugins, | |
09071200 | 210 | listAvailablePlugins, |
8d2be0ed | 211 | installPlugin, |
09071200 | 212 | getPluginsCSS, |
b5f919ac | 213 | updatePlugin, |
8d2be0ed C |
214 | getPlugin, |
215 | uninstallPlugin, | |
09071200 C |
216 | updatePluginSettings, |
217 | getPluginRegisteredSettings, | |
218 | getPackageJSONPath, | |
219 | updatePluginPackageJSON, | |
89cd1275 C |
220 | getPluginPackageJSON, |
221 | getPluginTestPath | |
8d2be0ed | 222 | } |