diff options
Diffstat (limited to 'server/tools/peertube-plugins.ts')
-rw-r--r-- | server/tools/peertube-plugins.ts | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts index 54ea1264d..d9c285115 100644 --- a/server/tools/peertube-plugins.ts +++ b/server/tools/peertube-plugins.ts | |||
@@ -4,9 +4,8 @@ import { registerTSPaths } from '../helpers/register-ts-paths' | |||
4 | registerTSPaths() | 4 | registerTSPaths() |
5 | 5 | ||
6 | import { program, Command, OptionValues } from 'commander' | 6 | import { program, Command, OptionValues } from 'commander' |
7 | import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins' | 7 | import { assignToken, buildServer, getServerCredentials } from './cli' |
8 | import { getAdminTokenOrDie, getServerCredentials } from './cli' | 8 | import { PluginType } from '../../shared/models' |
9 | import { PeerTubePlugin, PluginType } from '../../shared/models' | ||
10 | import { isAbsolute } from 'path' | 9 | import { isAbsolute } from 'path' |
11 | import * as CliTable3 from 'cli-table3' | 10 | import * as CliTable3 from 'cli-table3' |
12 | 11 | ||
@@ -63,28 +62,21 @@ program.parse(process.argv) | |||
63 | 62 | ||
64 | async function pluginsListCLI (command: Command, options: OptionValues) { | 63 | async function pluginsListCLI (command: Command, options: OptionValues) { |
65 | const { url, username, password } = await getServerCredentials(command) | 64 | const { url, username, password } = await getServerCredentials(command) |
66 | const accessToken = await getAdminTokenOrDie(url, username, password) | 65 | const server = buildServer(url) |
66 | await assignToken(server, username, password) | ||
67 | 67 | ||
68 | let pluginType: PluginType | 68 | let pluginType: PluginType |
69 | if (options.onlyThemes) pluginType = PluginType.THEME | 69 | if (options.onlyThemes) pluginType = PluginType.THEME |
70 | if (options.onlyPlugins) pluginType = PluginType.PLUGIN | 70 | if (options.onlyPlugins) pluginType = PluginType.PLUGIN |
71 | 71 | ||
72 | const res = await listPlugins({ | 72 | const { data } = await server.plugins.list({ start: 0, count: 100, sort: 'name', pluginType }) |
73 | url, | ||
74 | accessToken, | ||
75 | start: 0, | ||
76 | count: 100, | ||
77 | sort: 'name', | ||
78 | pluginType | ||
79 | }) | ||
80 | const plugins: PeerTubePlugin[] = res.body.data | ||
81 | 73 | ||
82 | const table = new CliTable3({ | 74 | const table = new CliTable3({ |
83 | head: [ 'name', 'version', 'homepage' ], | 75 | head: [ 'name', 'version', 'homepage' ], |
84 | colWidths: [ 50, 10, 50 ] | 76 | colWidths: [ 50, 10, 50 ] |
85 | }) as any | 77 | }) as any |
86 | 78 | ||
87 | for (const plugin of plugins) { | 79 | for (const plugin of data) { |
88 | const npmName = plugin.type === PluginType.PLUGIN | 80 | const npmName = plugin.type === PluginType.PLUGIN |
89 | ? 'peertube-plugin-' + plugin.name | 81 | ? 'peertube-plugin-' + plugin.name |
90 | : 'peertube-theme-' + plugin.name | 82 | : 'peertube-theme-' + plugin.name |
@@ -113,15 +105,11 @@ async function installPluginCLI (command: Command, options: OptionValues) { | |||
113 | } | 105 | } |
114 | 106 | ||
115 | const { url, username, password } = await getServerCredentials(command) | 107 | const { url, username, password } = await getServerCredentials(command) |
116 | const accessToken = await getAdminTokenOrDie(url, username, password) | 108 | const server = buildServer(url) |
109 | await assignToken(server, username, password) | ||
117 | 110 | ||
118 | try { | 111 | try { |
119 | await installPlugin({ | 112 | await server.plugins.install({ npmName: options.npmName, path: options.path }) |
120 | url, | ||
121 | accessToken, | ||
122 | npmName: options.npmName, | ||
123 | path: options.path | ||
124 | }) | ||
125 | } catch (err) { | 113 | } catch (err) { |
126 | console.error('Cannot install plugin.', err) | 114 | console.error('Cannot install plugin.', err) |
127 | process.exit(-1) | 115 | process.exit(-1) |
@@ -144,15 +132,11 @@ async function updatePluginCLI (command: Command, options: OptionValues) { | |||
144 | } | 132 | } |
145 | 133 | ||
146 | const { url, username, password } = await getServerCredentials(command) | 134 | const { url, username, password } = await getServerCredentials(command) |
147 | const accessToken = await getAdminTokenOrDie(url, username, password) | 135 | const server = buildServer(url) |
136 | await assignToken(server, username, password) | ||
148 | 137 | ||
149 | try { | 138 | try { |
150 | await updatePlugin({ | 139 | await server.plugins.update({ npmName: options.npmName, path: options.path }) |
151 | url, | ||
152 | accessToken, | ||
153 | npmName: options.npmName, | ||
154 | path: options.path | ||
155 | }) | ||
156 | } catch (err) { | 140 | } catch (err) { |
157 | console.error('Cannot update plugin.', err) | 141 | console.error('Cannot update plugin.', err) |
158 | process.exit(-1) | 142 | process.exit(-1) |
@@ -170,14 +154,11 @@ async function uninstallPluginCLI (command: Command, options: OptionValues) { | |||
170 | } | 154 | } |
171 | 155 | ||
172 | const { url, username, password } = await getServerCredentials(command) | 156 | const { url, username, password } = await getServerCredentials(command) |
173 | const accessToken = await getAdminTokenOrDie(url, username, password) | 157 | const server = buildServer(url) |
158 | await assignToken(server, username, password) | ||
174 | 159 | ||
175 | try { | 160 | try { |
176 | await uninstallPlugin({ | 161 | await server.plugins.uninstall({ npmName: options.npmName }) |
177 | url, | ||
178 | accessToken, | ||
179 | npmName: options.npmName | ||
180 | }) | ||
181 | } catch (err) { | 162 | } catch (err) { |
182 | console.error('Cannot uninstall plugin.', err) | 163 | console.error('Cannot uninstall plugin.', err) |
183 | process.exit(-1) | 164 | process.exit(-1) |