diff options
Diffstat (limited to 'server/tools/peertube-plugins.ts')
-rw-r--r-- | server/tools/peertube-plugins.ts | 25 |
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 | ||
4 | import * as program from 'commander' | 4 | import * as program from 'commander' |
5 | import { PluginType } from '../../shared/models/plugins/plugin.type' | 5 | import { PluginType } from '../../shared/models/plugins/plugin.type' |
6 | import { getAccessToken } from '../../shared/extra-utils/users/login' | ||
7 | import { getMyUserInformation } from '../../shared/extra-utils/users/users' | ||
8 | import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins' | 6 | import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins' |
9 | import { getServerCredentials } from './cli' | 7 | import { getAdminTokenOrDie, getServerCredentials } from './cli' |
10 | import { User, UserRole } from '../../shared/models/users' | ||
11 | import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' | 8 | import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' |
12 | import { isAbsolute } from 'path' | 9 | import { isAbsolute } from 'path' |
13 | 10 | import * as CliTable3 from 'cli-table3' | |
14 | const Table = require('cli-table') | ||
15 | 11 | ||
16 | program | 12 | program |
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 | |||
196 | async 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 | } | ||