]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tools/peertube-plugins.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-plugins.ts
index e40606107249e5b7ab8ea81be2dd14c5b9cfbd4e..05b75fab2b3429829bf64a0c99dbae20f31353d4 100644 (file)
@@ -1,17 +1,15 @@
+// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
+
 import { registerTSPaths } from '../helpers/register-ts-paths'
 registerTSPaths()
 
 import * as program from 'commander'
 import { PluginType } from '../../shared/models/plugins/plugin.type'
-import { getAccessToken } from '../../shared/extra-utils/users/login'
-import { getMyUserInformation } from '../../shared/extra-utils/users/users'
 import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins'
-import { getServerCredentials } from './cli'
-import { User, UserRole } from '../../shared/models/users'
+import { getAdminTokenOrDie, getServerCredentials } from './cli'
 import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model'
 import { isAbsolute } from 'path'
-
-const Table = require('cli-table')
+import * as CliTable3 from 'cli-table3'
 
 program
   .name('plugins')
@@ -82,10 +80,10 @@ async function pluginsListCLI () {
   })
   const plugins: PeerTubePlugin[] = res.body.data
 
-  const table = new Table({
-    head: ['name', 'version', 'homepage'],
+  const table = new CliTable3({
+    head: [ 'name', 'version', 'homepage' ],
     colWidths: [ 50, 10, 50 ]
-  })
+  }) as any
 
   for (const plugin of plugins) {
     const npmName = plugin.type === PluginType.PLUGIN
@@ -128,7 +126,6 @@ async function installPluginCLI (options: any) {
   } catch (err) {
     console.error('Cannot install plugin.', err)
     process.exit(-1)
-    return
   }
 
   console.log('Plugin installed.')
@@ -160,7 +157,6 @@ async function updatePluginCLI (options: any) {
   } catch (err) {
     console.error('Cannot update plugin.', err)
     process.exit(-1)
-    return
   }
 
   console.log('Plugin updated.')
@@ -181,27 +177,13 @@ async function uninstallPluginCLI (options: any) {
     await uninstallPlugin({
       url,
       accessToken,
-      npmName: options[ 'npmName' ]
+      npmName: options['npmName']
     })
   } catch (err) {
     console.error('Cannot uninstall plugin.', err)
     process.exit(-1)
-    return
   }
 
   console.log('Plugin uninstalled.')
   process.exit(0)
 }
-
-async function getAdminTokenOrDie (url: string, username: string, password: string) {
-  const accessToken = await getAccessToken(url, username, password)
-  const resMe = await getMyUserInformation(url, accessToken)
-  const me: User = resMe.body
-
-  if (me.role !== UserRole.ADMINISTRATOR) {
-    console.error('Cannot list plugins if you are not administrator.')
-    process.exit(-1)
-  }
-
-  return accessToken
-}