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.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/server/tools/peertube-redundancy.ts b/server/tools/peertube-redundancy.ts
index a71f48104..1ab58a438 100644
--- a/server/tools/peertube-redundancy.ts
+++ b/server/tools/peertube-redundancy.ts
@@ -1,3 +1,5 @@
1// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
2
1import { registerTSPaths } from '../helpers/register-ts-paths' 3import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths() 4registerTSPaths()
3 5
@@ -6,11 +8,12 @@ import { getAdminTokenOrDie, getServerCredentials } from './cli'
6import { VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' 8import { VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
7import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy } from '@shared/extra-utils/server/redundancy' 9import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy } from '@shared/extra-utils/server/redundancy'
8import validator from 'validator' 10import validator from 'validator'
9import bytes = require('bytes')
10import * as CliTable3 from 'cli-table3' 11import * as CliTable3 from 'cli-table3'
11import { parse } from 'url' 12import { URL } from 'url'
12import { uniq } from 'lodash' 13import { uniq } from 'lodash'
13 14
15import bytes = require('bytes')
16
14program 17program
15 .name('plugins') 18 .name('plugins')
16 .usage('[command] [options]') 19 .usage('[command] [options]')
@@ -65,7 +68,7 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) {
65 68
66 const table = new CliTable3({ 69 const table = new CliTable3({
67 head: [ 'video id', 'video name', 'video url', 'files', 'playlists', 'by instances', 'total size' ] 70 head: [ 'video id', 'video name', 'video url', 'files', 'playlists', 'by instances', 'total size' ]
68 }) as CliTable3.HorizontalTable 71 }) as any
69 72
70 for (const redundancy of redundancies) { 73 for (const redundancy of redundancies) {
71 const webtorrentFiles = redundancy.redundancies.files 74 const webtorrentFiles = redundancy.redundancies.files
@@ -82,7 +85,7 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) {
82 const instances = uniq( 85 const instances = uniq(
83 webtorrentFiles.concat(streamingPlaylists) 86 webtorrentFiles.concat(streamingPlaylists)
84 .map(r => r.fileUrl) 87 .map(r => r.fileUrl)
85 .map(u => parse(u).host) 88 .map(u => new URL(u).host)
86 ) 89 )
87 90
88 table.push([ 91 table.push([
@@ -104,7 +107,7 @@ async function addRedundancyCLI (options: { videoId: number }) {
104 const { url, username, password } = await getServerCredentials(program) 107 const { url, username, password } = await getServerCredentials(program)
105 const accessToken = await getAdminTokenOrDie(url, username, password) 108 const accessToken = await getAdminTokenOrDie(url, username, password)
106 109
107 if (!options[ 'video' ] || validator.isInt('' + options[ 'video' ]) === false) { 110 if (!options['video'] || validator.isInt('' + options['video']) === false) {
108 console.error('You need to specify the video id to duplicate and it should be a number.\n') 111 console.error('You need to specify the video id to duplicate and it should be a number.\n')
109 program.outputHelp() 112 program.outputHelp()
110 process.exit(-1) 113 process.exit(-1)
@@ -114,7 +117,7 @@ async function addRedundancyCLI (options: { videoId: number }) {
114 await addVideoRedundancy({ 117 await addVideoRedundancy({
115 url, 118 url,
116 accessToken, 119 accessToken,
117 videoId: options[ 'video' ] 120 videoId: options['video']
118 }) 121 })
119 122
120 console.log('Video will be duplicated by your instance!') 123 console.log('Video will be duplicated by your instance!')
@@ -137,13 +140,13 @@ async function removeRedundancyCLI (options: { videoId: number }) {
137 const { url, username, password } = await getServerCredentials(program) 140 const { url, username, password } = await getServerCredentials(program)
138 const accessToken = await getAdminTokenOrDie(url, username, password) 141 const accessToken = await getAdminTokenOrDie(url, username, password)
139 142
140 if (!options[ 'video' ] || validator.isInt('' + options[ 'video' ]) === false) { 143 if (!options['video'] || validator.isInt('' + options['video']) === false) {
141 console.error('You need to specify the video id to remove from your redundancies.\n') 144 console.error('You need to specify the video id to remove from your redundancies.\n')
142 program.outputHelp() 145 program.outputHelp()
143 process.exit(-1) 146 process.exit(-1)
144 } 147 }
145 148
146 const videoId = parseInt(options[ 'video' ] + '', 10) 149 const videoId = parseInt(options['video'] + '', 10)
147 150
148 let redundancies = await listVideoRedundanciesData(url, accessToken, 'my-videos') 151 let redundancies = await listVideoRedundanciesData(url, accessToken, 'my-videos')
149 let videoRedundancy = redundancies.find(r => videoId === r.id) 152 let videoRedundancy = redundancies.find(r => videoId === r.id)