diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-09 15:03:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 078f17e6d90376050f43ce639e88e11869b49ee7 (patch) | |
tree | 1aeef2c43591de2f72b84b85672de8e83815e8fa /server/tools/cli.ts | |
parent | 12edc1495a36b2199f1bf1ba37f50c7b694be382 (diff) | |
download | PeerTube-078f17e6d90376050f43ce639e88e11869b49ee7.tar.gz PeerTube-078f17e6d90376050f43ce639e88e11869b49ee7.tar.zst PeerTube-078f17e6d90376050f43ce639e88e11869b49ee7.zip |
Fix CLI tools
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r-- | server/tools/cli.ts | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 7b94306cd..0528859a4 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import { Command } from 'commander' | ||
1 | import { Netrc } from 'netrc-parser' | 2 | import { Netrc } from 'netrc-parser' |
2 | import { getAppNumber, isTestInstance } from '../helpers/core-utils' | ||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { root } from '../../shared/extra-utils/miscs/miscs' | ||
5 | import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels' | ||
6 | import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' | ||
7 | import { createLogger, format, transports } from 'winston' | 4 | import { createLogger, format, transports } from 'winston' |
5 | import { assignCommands, ServerInfo } from '@shared/extra-utils' | ||
6 | import { getAccessToken } from '@shared/extra-utils/users/login' | ||
8 | import { getMyUserInformation } from '@shared/extra-utils/users/users' | 7 | import { getMyUserInformation } from '@shared/extra-utils/users/users' |
9 | import { User, UserRole } from '@shared/models' | 8 | import { User, UserRole } from '@shared/models' |
10 | import { getAccessToken } from '@shared/extra-utils/users/login' | 9 | import { root } from '../../shared/extra-utils/miscs/miscs' |
11 | import { Command } from 'commander' | 10 | import { VideoPrivacy } from '../../shared/models/videos' |
11 | import { getAppNumber, isTestInstance } from '../helpers/core-utils' | ||
12 | 12 | ||
13 | let configName = 'PeerTube/CLI' | 13 | let configName = 'PeerTube/CLI' |
14 | if (isTestInstance()) configName += `-${getAppNumber()}` | 14 | if (isTestInstance()) configName += `-${getAppNumber()}` |
@@ -30,6 +30,10 @@ async function getAdminTokenOrDie (url: string, username: string, password: stri | |||
30 | return accessToken | 30 | return accessToken |
31 | } | 31 | } |
32 | 32 | ||
33 | async function getAccessTokenOrDie (url: string, username: string, password: string) { | ||
34 | return getAccessToken(url, username, password) | ||
35 | } | ||
36 | |||
33 | interface Settings { | 37 | interface Settings { |
34 | remotes: any[] | 38 | remotes: any[] |
35 | default: number | 39 | default: number |
@@ -128,7 +132,7 @@ function buildCommonVideoOptions (command: Command) { | |||
128 | .option('-v, --verbose <verbose>', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info') | 132 | .option('-v, --verbose <verbose>', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info') |
129 | } | 133 | } |
130 | 134 | ||
131 | async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any = {}) { | 135 | async function buildVideoAttributesFromCommander (server: ServerInfo, command: Command, defaultAttributes: any = {}) { |
132 | const options = command.opts() | 136 | const options = command.opts() |
133 | 137 | ||
134 | const defaultBooleanAttributes = { | 138 | const defaultBooleanAttributes = { |
@@ -164,8 +168,7 @@ async function buildVideoAttributesFromCommander (url: string, command: Command, | |||
164 | Object.assign(videoAttributes, booleanAttributes) | 168 | Object.assign(videoAttributes, booleanAttributes) |
165 | 169 | ||
166 | if (options.channelName) { | 170 | if (options.channelName) { |
167 | const res = await getVideoChannel(url, options.channelName) | 171 | const videoChannel = await server.channelsCommand.get({ channelName: options.channelName }) |
168 | const videoChannel: VideoChannel = res.body | ||
169 | 172 | ||
170 | Object.assign(videoAttributes, { channelId: videoChannel.id }) | 173 | Object.assign(videoAttributes, { channelId: videoChannel.id }) |
171 | 174 | ||
@@ -184,6 +187,13 @@ function getServerCredentials (program: Command) { | |||
184 | }) | 187 | }) |
185 | } | 188 | } |
186 | 189 | ||
190 | function buildServer (url: string, accessToken?: string): ServerInfo { | ||
191 | const server = { url, accessToken, internalServerNumber: undefined } | ||
192 | assignCommands(server) | ||
193 | |||
194 | return server | ||
195 | } | ||
196 | |||
187 | function getLogger (logLevel = 'info') { | 197 | function getLogger (logLevel = 'info') { |
188 | const logLevels = { | 198 | const logLevels = { |
189 | 0: 0, | 199 | 0: 0, |
@@ -230,5 +240,7 @@ export { | |||
230 | buildCommonVideoOptions, | 240 | buildCommonVideoOptions, |
231 | buildVideoAttributesFromCommander, | 241 | buildVideoAttributesFromCommander, |
232 | 242 | ||
233 | getAdminTokenOrDie | 243 | getAdminTokenOrDie, |
244 | getAccessTokenOrDie, | ||
245 | buildServer | ||
234 | } | 246 | } |