aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-plugins.ts')
-rw-r--r--server/tools/peertube-plugins.ts34
1 files changed, 8 insertions, 26 deletions
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts
index e40606107..05b75fab2 100644
--- a/server/tools/peertube-plugins.ts
+++ b/server/tools/peertube-plugins.ts
@@ -1,17 +1,15 @@
1// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
2
1import { registerTSPaths } from '../helpers/register-ts-paths' 3import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths() 4registerTSPaths()
3 5
4import * as program from 'commander' 6import * as program from 'commander'
5import { PluginType } from '../../shared/models/plugins/plugin.type' 7import { PluginType } from '../../shared/models/plugins/plugin.type'
6import { getAccessToken } from '../../shared/extra-utils/users/login'
7import { getMyUserInformation } from '../../shared/extra-utils/users/users'
8import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins' 8import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins'
9import { getServerCredentials } from './cli' 9import { getAdminTokenOrDie, getServerCredentials } from './cli'
10import { User, UserRole } from '../../shared/models/users'
11import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' 10import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model'
12import { isAbsolute } from 'path' 11import { isAbsolute } from 'path'
13 12import * as CliTable3 from 'cli-table3'
14const Table = require('cli-table')
15 13
16program 14program
17 .name('plugins') 15 .name('plugins')
@@ -82,10 +80,10 @@ async function pluginsListCLI () {
82 }) 80 })
83 const plugins: PeerTubePlugin[] = res.body.data 81 const plugins: PeerTubePlugin[] = res.body.data
84 82
85 const table = new Table({ 83 const table = new CliTable3({
86 head: ['name', 'version', 'homepage'], 84 head: [ 'name', 'version', 'homepage' ],
87 colWidths: [ 50, 10, 50 ] 85 colWidths: [ 50, 10, 50 ]
88 }) 86 }) as any
89 87
90 for (const plugin of plugins) { 88 for (const plugin of plugins) {
91 const npmName = plugin.type === PluginType.PLUGIN 89 const npmName = plugin.type === PluginType.PLUGIN
@@ -128,7 +126,6 @@ async function installPluginCLI (options: any) {
128 } catch (err) { 126 } catch (err) {
129 console.error('Cannot install plugin.', err) 127 console.error('Cannot install plugin.', err)
130 process.exit(-1) 128 process.exit(-1)
131 return
132 } 129 }
133 130
134 console.log('Plugin installed.') 131 console.log('Plugin installed.')
@@ -160,7 +157,6 @@ async function updatePluginCLI (options: any) {
160 } catch (err) { 157 } catch (err) {
161 console.error('Cannot update plugin.', err) 158 console.error('Cannot update plugin.', err)
162 process.exit(-1) 159 process.exit(-1)
163 return
164 } 160 }
165 161
166 console.log('Plugin updated.') 162 console.log('Plugin updated.')
@@ -181,27 +177,13 @@ async function uninstallPluginCLI (options: any) {
181 await uninstallPlugin({ 177 await uninstallPlugin({
182 url, 178 url,
183 accessToken, 179 accessToken,
184 npmName: options[ 'npmName' ] 180 npmName: options['npmName']
185 }) 181 })
186 } catch (err) { 182 } catch (err) {
187 console.error('Cannot uninstall plugin.', err) 183 console.error('Cannot uninstall plugin.', err)
188 process.exit(-1) 184 process.exit(-1)
189 return
190 } 185 }
191 186
192 console.log('Plugin uninstalled.') 187 console.log('Plugin uninstalled.')
193 process.exit(0) 188 process.exit(0)
194} 189}
195
196async function getAdminTokenOrDie (url: string, username: string, password: string) {
197 const accessToken = await getAccessToken(url, username, password)
198 const resMe = await getMyUserInformation(url, accessToken)
199 const me: User = resMe.body
200
201 if (me.role !== UserRole.ADMINISTRATOR) {
202 console.error('Cannot list plugins if you are not administrator.')
203 process.exit(-1)
204 }
205
206 return accessToken
207}