aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-redundancy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-redundancy.ts')
-rw-r--r--server/tools/peertube-redundancy.ts25
1 files changed, 13 insertions, 12 deletions
diff --git a/server/tools/peertube-redundancy.ts b/server/tools/peertube-redundancy.ts
index fe482daf4..5bc80ddb9 100644
--- a/server/tools/peertube-redundancy.ts
+++ b/server/tools/peertube-redundancy.ts
@@ -14,6 +14,7 @@ import { URL } from 'url'
14import { uniq } from 'lodash' 14import { uniq } from 'lodash'
15 15
16import bytes = require('bytes') 16import bytes = require('bytes')
17import commander = require('commander')
17 18
18program 19program
19 .name('plugins') 20 .name('plugins')
@@ -42,7 +43,7 @@ program
42 .option('-U, --username <username>', 'Username') 43 .option('-U, --username <username>', 'Username')
43 .option('-p, --password <token>', 'Password') 44 .option('-p, --password <token>', 'Password')
44 .option('-v, --video <videoId>', 'Video id to duplicate') 45 .option('-v, --video <videoId>', 'Video id to duplicate')
45 .action((options) => addRedundancyCLI(options)) 46 .action((options, command) => addRedundancyCLI(options, command))
46 47
47program 48program
48 .command('remove') 49 .command('remove')
@@ -51,7 +52,7 @@ program
51 .option('-U, --username <username>', 'Username') 52 .option('-U, --username <username>', 'Username')
52 .option('-p, --password <token>', 'Password') 53 .option('-p, --password <token>', 'Password')
53 .option('-v, --video <videoId>', 'Video id to remove from redundancies') 54 .option('-v, --video <videoId>', 'Video id to remove from redundancies')
54 .action((options) => removeRedundancyCLI(options)) 55 .action((options, command) => removeRedundancyCLI(options, command))
55 56
56if (!process.argv.slice(2).length) { 57if (!process.argv.slice(2).length) {
57 program.outputHelp() 58 program.outputHelp()
@@ -104,13 +105,13 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) {
104 process.exit(0) 105 process.exit(0)
105} 106}
106 107
107async function addRedundancyCLI (options: { videoId: number }) { 108async function addRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) {
108 const { url, username, password } = await getServerCredentials(program) 109 const { url, username, password } = await getServerCredentials(command)
109 const accessToken = await getAdminTokenOrDie(url, username, password) 110 const accessToken = await getAdminTokenOrDie(url, username, password)
110 111
111 if (!options['video'] || validator.isInt('' + options['video']) === false) { 112 if (!options.video || validator.isInt('' + options.video) === false) {
112 console.error('You need to specify the video id to duplicate and it should be a number.\n') 113 console.error('You need to specify the video id to duplicate and it should be a number.\n')
113 program.outputHelp() 114 command.outputHelp()
114 process.exit(-1) 115 process.exit(-1)
115 } 116 }
116 117
@@ -118,7 +119,7 @@ async function addRedundancyCLI (options: { videoId: number }) {
118 await addVideoRedundancy({ 119 await addVideoRedundancy({
119 url, 120 url,
120 accessToken, 121 accessToken,
121 videoId: options['video'] 122 videoId: options.video
122 }) 123 })
123 124
124 console.log('Video will be duplicated by your instance!') 125 console.log('Video will be duplicated by your instance!')
@@ -137,17 +138,17 @@ async function addRedundancyCLI (options: { videoId: number }) {
137 } 138 }
138} 139}
139 140
140async function removeRedundancyCLI (options: { videoId: number }) { 141async function removeRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) {
141 const { url, username, password } = await getServerCredentials(program) 142 const { url, username, password } = await getServerCredentials(command)
142 const accessToken = await getAdminTokenOrDie(url, username, password) 143 const accessToken = await getAdminTokenOrDie(url, username, password)
143 144
144 if (!options['video'] || validator.isInt('' + options['video']) === false) { 145 if (!options.video || validator.isInt('' + options.video) === false) {
145 console.error('You need to specify the video id to remove from your redundancies.\n') 146 console.error('You need to specify the video id to remove from your redundancies.\n')
146 program.outputHelp() 147 command.outputHelp()
147 process.exit(-1) 148 process.exit(-1)
148 } 149 }
149 150
150 const videoId = parseInt(options['video'] + '', 10) 151 const videoId = parseInt(options.video + '', 10)
151 152
152 let redundancies = await listVideoRedundanciesData(url, accessToken, 'my-videos') 153 let redundancies = await listVideoRedundanciesData(url, accessToken, 'my-videos')
153 let videoRedundancy = redundancies.find(r => videoId === r.id) 154 let videoRedundancy = redundancies.find(r => videoId === r.id)