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.ts25
1 files changed, 4 insertions, 21 deletions
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts
index e40606107..b341c14c1 100644
--- a/server/tools/peertube-plugins.ts
+++ b/server/tools/peertube-plugins.ts
@@ -3,15 +3,11 @@ registerTSPaths()
3 3
4import * as program from 'commander' 4import * as program from 'commander'
5import { PluginType } from '../../shared/models/plugins/plugin.type' 5import { 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' 6import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins'
9import { getServerCredentials } from './cli' 7import { getAdminTokenOrDie, getServerCredentials } from './cli'
10import { User, UserRole } from '../../shared/models/users'
11import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' 8import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model'
12import { isAbsolute } from 'path' 9import { isAbsolute } from 'path'
13 10import * as CliTable3 from 'cli-table3'
14const Table = require('cli-table')
15 11
16program 12program
17 .name('plugins') 13 .name('plugins')
@@ -82,10 +78,10 @@ async function pluginsListCLI () {
82 }) 78 })
83 const plugins: PeerTubePlugin[] = res.body.data 79 const plugins: PeerTubePlugin[] = res.body.data
84 80
85 const table = new Table({ 81 const table = new CliTable3({
86 head: ['name', 'version', 'homepage'], 82 head: ['name', 'version', 'homepage'],
87 colWidths: [ 50, 10, 50 ] 83 colWidths: [ 50, 10, 50 ]
88 }) 84 }) as CliTable3.HorizontalTable
89 85
90 for (const plugin of plugins) { 86 for (const plugin of plugins) {
91 const npmName = plugin.type === PluginType.PLUGIN 87 const npmName = plugin.type === PluginType.PLUGIN
@@ -192,16 +188,3 @@ async function uninstallPluginCLI (options: any) {
192 console.log('Plugin uninstalled.') 188 console.log('Plugin uninstalled.')
193 process.exit(0) 189 process.exit(0)
194} 190}
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}