aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 15:03:44 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit078f17e6d90376050f43ce639e88e11869b49ee7 (patch)
tree1aeef2c43591de2f72b84b85672de8e83815e8fa /server/tools/cli.ts
parent12edc1495a36b2199f1bf1ba37f50c7b694be382 (diff)
downloadPeerTube-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.ts32
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 @@
1import { Command } from 'commander'
1import { Netrc } from 'netrc-parser' 2import { Netrc } from 'netrc-parser'
2import { getAppNumber, isTestInstance } from '../helpers/core-utils'
3import { join } from 'path' 3import { join } from 'path'
4import { root } from '../../shared/extra-utils/miscs/miscs'
5import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels'
6import { VideoChannel, VideoPrivacy } from '../../shared/models/videos'
7import { createLogger, format, transports } from 'winston' 4import { createLogger, format, transports } from 'winston'
5import { assignCommands, ServerInfo } from '@shared/extra-utils'
6import { getAccessToken } from '@shared/extra-utils/users/login'
8import { getMyUserInformation } from '@shared/extra-utils/users/users' 7import { getMyUserInformation } from '@shared/extra-utils/users/users'
9import { User, UserRole } from '@shared/models' 8import { User, UserRole } from '@shared/models'
10import { getAccessToken } from '@shared/extra-utils/users/login' 9import { root } from '../../shared/extra-utils/miscs/miscs'
11import { Command } from 'commander' 10import { VideoPrivacy } from '../../shared/models/videos'
11import { getAppNumber, isTestInstance } from '../helpers/core-utils'
12 12
13let configName = 'PeerTube/CLI' 13let configName = 'PeerTube/CLI'
14if (isTestInstance()) configName += `-${getAppNumber()}` 14if (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
33async function getAccessTokenOrDie (url: string, username: string, password: string) {
34 return getAccessToken(url, username, password)
35}
36
33interface Settings { 37interface 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
131async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any = {}) { 135async 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
190function buildServer (url: string, accessToken?: string): ServerInfo {
191 const server = { url, accessToken, internalServerNumber: undefined }
192 assignCommands(server)
193
194 return server
195}
196
187function getLogger (logLevel = 'info') { 197function 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}