diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 17:23:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch) | |
tree | 31a36b252df32be83ceb77658a53b57f9d15e8ac /shared/extra-utils/server/plugins.ts | |
parent | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff) | |
download | PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip |
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'shared/extra-utils/server/plugins.ts')
-rw-r--r-- | shared/extra-utils/server/plugins.ts | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts new file mode 100644 index 000000000..6cd7cd17a --- /dev/null +++ b/shared/extra-utils/server/plugins.ts | |||
@@ -0,0 +1,125 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest } from '../requests/requests' | ||
2 | import { PluginType } from '../../models/plugins/plugin.type' | ||
3 | |||
4 | function listPlugins (parameters: { | ||
5 | url: string, | ||
6 | accessToken: string, | ||
7 | start?: number, | ||
8 | count?: number, | ||
9 | sort?: string, | ||
10 | type?: PluginType, | ||
11 | expectedStatus?: number | ||
12 | }) { | ||
13 | const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters | ||
14 | const path = '/api/v1/plugins' | ||
15 | |||
16 | return makeGetRequest({ | ||
17 | url, | ||
18 | path, | ||
19 | token: accessToken, | ||
20 | query: { | ||
21 | start, | ||
22 | count, | ||
23 | sort, | ||
24 | type | ||
25 | }, | ||
26 | statusCodeExpected: expectedStatus | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | function getPlugin (parameters: { | ||
31 | url: string, | ||
32 | accessToken: string, | ||
33 | npmName: string, | ||
34 | expectedStatus?: number | ||
35 | }) { | ||
36 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | ||
37 | const path = '/api/v1/plugins/' + npmName | ||
38 | |||
39 | return makeGetRequest({ | ||
40 | url, | ||
41 | path, | ||
42 | token: accessToken, | ||
43 | statusCodeExpected: expectedStatus | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | function getPluginSettings (parameters: { | ||
48 | url: string, | ||
49 | accessToken: string, | ||
50 | npmName: string, | ||
51 | expectedStatus?: number | ||
52 | }) { | ||
53 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | ||
54 | const path = '/api/v1/plugins/' + npmName + '/settings' | ||
55 | |||
56 | return makeGetRequest({ | ||
57 | url, | ||
58 | path, | ||
59 | token: accessToken, | ||
60 | statusCodeExpected: expectedStatus | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | function getPluginRegisteredSettings (parameters: { | ||
65 | url: string, | ||
66 | accessToken: string, | ||
67 | npmName: string, | ||
68 | expectedStatus?: number | ||
69 | }) { | ||
70 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | ||
71 | const path = '/api/v1/plugins/' + npmName + '/registered-settings' | ||
72 | |||
73 | return makeGetRequest({ | ||
74 | url, | ||
75 | path, | ||
76 | token: accessToken, | ||
77 | statusCodeExpected: expectedStatus | ||
78 | }) | ||
79 | } | ||
80 | |||
81 | function installPlugin (parameters: { | ||
82 | url: string, | ||
83 | accessToken: string, | ||
84 | path?: string, | ||
85 | npmName?: string | ||
86 | expectedStatus?: number | ||
87 | }) { | ||
88 | const { url, accessToken, npmName, path, expectedStatus = 204 } = parameters | ||
89 | const apiPath = '/api/v1/plugins/install' | ||
90 | |||
91 | return makePostBodyRequest({ | ||
92 | url, | ||
93 | path: apiPath, | ||
94 | token: accessToken, | ||
95 | fields: { npmName, path }, | ||
96 | statusCodeExpected: expectedStatus | ||
97 | }) | ||
98 | } | ||
99 | |||
100 | function uninstallPlugin (parameters: { | ||
101 | url: string, | ||
102 | accessToken: string, | ||
103 | npmName: string | ||
104 | expectedStatus?: number | ||
105 | }) { | ||
106 | const { url, accessToken, npmName, expectedStatus = 204 } = parameters | ||
107 | const apiPath = '/api/v1/plugins/uninstall' | ||
108 | |||
109 | return makePostBodyRequest({ | ||
110 | url, | ||
111 | path: apiPath, | ||
112 | token: accessToken, | ||
113 | fields: { npmName }, | ||
114 | statusCodeExpected: expectedStatus | ||
115 | }) | ||
116 | } | ||
117 | |||
118 | export { | ||
119 | listPlugins, | ||
120 | installPlugin, | ||
121 | getPlugin, | ||
122 | uninstallPlugin, | ||
123 | getPluginSettings, | ||
124 | getPluginRegisteredSettings | ||
125 | } | ||