aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-31 16:56:52 +0100
committerChocobozzz <me@florianbigard.com>2020-02-03 08:31:02 +0100
commita15871560f80e07386c1dabb8370cd2664ecfd1f (patch)
tree44440e140c9e43b0d7f97ade777a76e649e0553d /server/tools
parenta22046d166805222ca76060e471b6cb3d419a32d (diff)
downloadPeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.tar.gz
PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.tar.zst
PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.zip
Move to eslintcontain
Diffstat (limited to 'server/tools')
-rw-r--r--server/tools/cli.ts42
-rw-r--r--server/tools/peertube-auth.ts10
-rw-r--r--server/tools/peertube-import-videos.ts83
-rw-r--r--server/tools/peertube-plugins.ts11
-rw-r--r--server/tools/peertube-redundancy.ts19
-rw-r--r--server/tools/peertube-repl.ts41
-rw-r--r--server/tools/peertube-upload.ts21
-rw-r--r--server/tools/peertube-watch.ts10
-rw-r--r--server/tools/peertube.ts23
9 files changed, 138 insertions, 122 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
index 15ac6c6a8..d1a631b69 100644
--- a/server/tools/cli.ts
+++ b/server/tools/cli.ts
@@ -31,7 +31,7 @@ async function getAdminTokenOrDie (url: string, username: string, password: stri
31} 31}
32 32
33interface Settings { 33interface Settings {
34 remotes: any[], 34 remotes: any[]
35 default: number 35 default: number
36} 36}
37 37
@@ -90,9 +90,9 @@ function getRemoteObjectOrDie (
90 if (!program['url'] || !program['username'] || !program['password']) { 90 if (!program['url'] || !program['username'] || !program['password']) {
91 // No remote and we don't have program parameters: quit 91 // No remote and we don't have program parameters: quit
92 if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) { 92 if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) {
93 if (!program[ 'url' ]) console.error('--url field is required.') 93 if (!program['url']) console.error('--url field is required.')
94 if (!program[ 'username' ]) console.error('--username field is required.') 94 if (!program['username']) console.error('--username field is required.')
95 if (!program[ 'password' ]) console.error('--password field is required.') 95 if (!program['password']) console.error('--password field is required.')
96 96
97 return process.exit(-1) 97 return process.exit(-1)
98 } 98 }
@@ -112,9 +112,9 @@ function getRemoteObjectOrDie (
112 } 112 }
113 113
114 return { 114 return {
115 url: program[ 'url' ], 115 url: program['url'],
116 username: program[ 'username' ], 116 username: program['username'],
117 password: program[ 'password' ] 117 password: program['password']
118 } 118 }
119} 119}
120 120
@@ -150,8 +150,8 @@ async function buildVideoAttributesFromCommander (url: string, command: Command,
150 const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {} 150 const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {}
151 151
152 for (const key of Object.keys(defaultBooleanAttributes)) { 152 for (const key of Object.keys(defaultBooleanAttributes)) {
153 if (command[ key ] !== undefined) { 153 if (command[key] !== undefined) {
154 booleanAttributes[key] = command[ key ] 154 booleanAttributes[key] = command[key]
155 } else if (defaultAttributes[key] !== undefined) { 155 } else if (defaultAttributes[key] !== undefined) {
156 booleanAttributes[key] = defaultAttributes[key] 156 booleanAttributes[key] = defaultAttributes[key]
157 } else { 157 } else {
@@ -160,19 +160,19 @@ async function buildVideoAttributesFromCommander (url: string, command: Command,
160 } 160 }
161 161
162 const videoAttributes = { 162 const videoAttributes = {
163 name: command[ 'videoName' ] || defaultAttributes.name, 163 name: command['videoName'] || defaultAttributes.name,
164 category: command[ 'category' ] || defaultAttributes.category || undefined, 164 category: command['category'] || defaultAttributes.category || undefined,
165 licence: command[ 'licence' ] || defaultAttributes.licence || undefined, 165 licence: command['licence'] || defaultAttributes.licence || undefined,
166 language: command[ 'language' ] || defaultAttributes.language || undefined, 166 language: command['language'] || defaultAttributes.language || undefined,
167 privacy: command[ 'privacy' ] || defaultAttributes.privacy || VideoPrivacy.PUBLIC, 167 privacy: command['privacy'] || defaultAttributes.privacy || VideoPrivacy.PUBLIC,
168 support: command[ 'support' ] || defaultAttributes.support || undefined, 168 support: command['support'] || defaultAttributes.support || undefined,
169 description: command[ 'videoDescription' ] || defaultAttributes.description || undefined, 169 description: command['videoDescription'] || defaultAttributes.description || undefined,
170 tags: command[ 'tags' ] || defaultAttributes.tags || undefined 170 tags: command['tags'] || defaultAttributes.tags || undefined
171 } 171 }
172 172
173 Object.assign(videoAttributes, booleanAttributes) 173 Object.assign(videoAttributes, booleanAttributes)
174 174
175 if (command[ 'channelName' ]) { 175 if (command['channelName']) {
176 const res = await getVideoChannel(url, command['channelName']) 176 const res = await getVideoChannel(url, command['channelName'])
177 const videoChannel: VideoChannel = res.body 177 const videoChannel: VideoChannel = res.body
178 178
@@ -188,9 +188,9 @@ async function buildVideoAttributesFromCommander (url: string, command: Command,
188 188
189function getServerCredentials (program: any) { 189function getServerCredentials (program: any) {
190 return Promise.all([ getSettings(), getNetrc() ]) 190 return Promise.all([ getSettings(), getNetrc() ])
191 .then(([ settings, netrc ]) => { 191 .then(([ settings, netrc ]) => {
192 return getRemoteObjectOrDie(program, settings, netrc) 192 return getRemoteObjectOrDie(program, settings, netrc)
193 }) 193 })
194} 194}
195 195
196function getLogger (logLevel = 'info') { 196function getLogger (logLevel = 'info') {
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts
index acac75034..6b486e575 100644
--- a/server/tools/peertube-auth.ts
+++ b/server/tools/peertube-auth.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
@@ -5,7 +7,7 @@ import * as program from 'commander'
5import * as prompt from 'prompt' 7import * as prompt from 'prompt'
6import { getNetrc, getSettings, writeSettings } from './cli' 8import { getNetrc, getSettings, writeSettings } from './cli'
7import { isUserUsernameValid } from '../helpers/custom-validators/users' 9import { isUserUsernameValid } from '../helpers/custom-validators/users'
8import { getAccessToken, login } from '../../shared/extra-utils' 10import { getAccessToken } from '../../shared/extra-utils'
9import * as CliTable3 from 'cli-table3' 11import * as CliTable3 from 'cli-table3'
10 12
11async function delInstance (url: string) { 13async function delInstance (url: string) {
@@ -108,9 +110,9 @@ program
108 const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) 110 const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
109 111
110 const table = new CliTable3({ 112 const table = new CliTable3({
111 head: ['instance', 'login'], 113 head: [ 'instance', 'login' ],
112 colWidths: [30, 30] 114 colWidths: [ 30, 30 ]
113 }) as CliTable3.HorizontalTable 115 }) as any
114 116
115 settings.remotes.forEach(element => { 117 settings.remotes.forEach(element => {
116 if (!netrc.machines[element]) return 118 if (!netrc.machines[element]) return
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index c7e85b570..0efe87810 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -12,7 +12,7 @@ import { accessSync, constants } from 'fs'
12import { remove } from 'fs-extra' 12import { remove } from 'fs-extra'
13import { sha256 } from '../helpers/core-utils' 13import { sha256 } from '../helpers/core-utils'
14import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl' 14import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl'
15import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getServerCredentials, getLogger } from './cli' 15import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getLogger, getServerCredentials } from './cli'
16 16
17type UserInfo = { 17type UserInfo = {
18 username: string 18 username: string
@@ -40,30 +40,29 @@ command
40 .option('-T, --tmpdir <tmpdir>', 'Working directory', __dirname) 40 .option('-T, --tmpdir <tmpdir>', 'Working directory', __dirname)
41 .parse(process.argv) 41 .parse(process.argv)
42 42
43let log = getLogger(program[ 'verbose' ]) 43const log = getLogger(program['verbose'])
44 44
45getServerCredentials(command) 45getServerCredentials(command)
46 .then(({ url, username, password }) => { 46 .then(({ url, username, password }) => {
47 if (!program[ 'targetUrl' ]) { 47 if (!program['targetUrl']) {
48 exitError('--target-url field is required.') 48 exitError('--target-url field is required.')
49 } 49 }
50 50
51 try { 51 try {
52 accessSync(program[ 'tmpdir' ], constants.R_OK | constants.W_OK) 52 accessSync(program['tmpdir'], constants.R_OK | constants.W_OK)
53 } catch (e) { 53 } catch (e) {
54 exitError('--tmpdir %s: directory does not exist or is not accessible', program[ 'tmpdir' ]) 54 exitError('--tmpdir %s: directory does not exist or is not accessible', program['tmpdir'])
55 } 55 }
56 56
57 url = normalizeTargetUrl(url) 57 url = normalizeTargetUrl(url)
58 program[ 'targetUrl' ] = normalizeTargetUrl(program[ 'targetUrl' ]) 58 program['targetUrl'] = normalizeTargetUrl(program['targetUrl'])
59 59
60 const user = { username, password } 60 const user = { username, password }
61 61
62 run(url, user) 62 run(url, user)
63 .catch(err => { 63 .catch(err => exitError(err))
64 exitError(err)
65 })
66 }) 64 })
65 .catch(err => console.error(err))
67 66
68async function run (url: string, user: UserInfo) { 67async function run (url: string, user: UserInfo) {
69 if (!user.password) { 68 if (!user.password) {
@@ -73,7 +72,7 @@ async function run (url: string, user: UserInfo) {
73 const youtubeDL = await safeGetYoutubeDL() 72 const youtubeDL = await safeGetYoutubeDL()
74 73
75 const options = [ '-j', '--flat-playlist', '--playlist-reverse' ] 74 const options = [ '-j', '--flat-playlist', '--playlist-reverse' ]
76 youtubeDL.getInfo(program[ 'targetUrl' ], options, processOptions, async (err, info) => { 75 youtubeDL.getInfo(program['targetUrl'], options, processOptions, async (err, info) => {
77 if (err) { 76 if (err) {
78 exitError(err.message) 77 exitError(err.message)
79 } 78 }
@@ -82,10 +81,10 @@ async function run (url: string, user: UserInfo) {
82 81
83 // Normalize utf8 fields 82 // Normalize utf8 fields
84 infoArray = [].concat(info) 83 infoArray = [].concat(info)
85 if (program[ 'first' ]) { 84 if (program['first']) {
86 infoArray = infoArray.slice(0, program[ 'first' ]) 85 infoArray = infoArray.slice(0, program['first'])
87 } else if (program[ 'last' ]) { 86 } else if (program['last']) {
88 infoArray = infoArray.slice(-program[ 'last' ]) 87 infoArray = infoArray.slice(-program['last'])
89 } 88 }
90 infoArray = infoArray.map(i => normalizeObject(i)) 89 infoArray = infoArray.map(i => normalizeObject(i))
91 90
@@ -93,22 +92,22 @@ async function run (url: string, user: UserInfo) {
93 92
94 for (const info of infoArray) { 93 for (const info of infoArray) {
95 await processVideo({ 94 await processVideo({
96 cwd: program[ 'tmpdir' ], 95 cwd: program['tmpdir'],
97 url, 96 url,
98 user, 97 user,
99 youtubeInfo: info 98 youtubeInfo: info
100 }) 99 })
101 } 100 }
102 101
103 log.info('Video/s for user %s imported: %s', user.username, program[ 'targetUrl' ]) 102 log.info('Video/s for user %s imported: %s', user.username, program['targetUrl'])
104 process.exit(0) 103 process.exit(0)
105 }) 104 })
106} 105}
107 106
108function processVideo (parameters: { 107function processVideo (parameters: {
109 cwd: string, 108 cwd: string
110 url: string, 109 url: string
111 user: { username: string, password: string }, 110 user: { username: string, password: string }
112 youtubeInfo: any 111 youtubeInfo: any
113}) { 112}) {
114 const { youtubeInfo, cwd, url, user } = parameters 113 const { youtubeInfo, cwd, url, user } = parameters
@@ -119,17 +118,17 @@ function processVideo (parameters: {
119 const videoInfo = await fetchObject(youtubeInfo) 118 const videoInfo = await fetchObject(youtubeInfo)
120 log.debug('Fetched object.', videoInfo) 119 log.debug('Fetched object.', videoInfo)
121 120
122 if (program[ 'since' ]) { 121 if (program['since']) {
123 if (buildOriginallyPublishedAt(videoInfo).getTime() < program[ 'since' ].getTime()) { 122 if (buildOriginallyPublishedAt(videoInfo).getTime() < program['since'].getTime()) {
124 log.info('Video "%s" has been published before "%s", don\'t upload it.\n', 123 log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
125 videoInfo.title, formatDate(program[ 'since' ])) 124 videoInfo.title, formatDate(program['since']))
126 return res() 125 return res()
127 } 126 }
128 } 127 }
129 if (program[ 'until' ]) { 128 if (program['until']) {
130 if (buildOriginallyPublishedAt(videoInfo).getTime() > program[ 'until' ].getTime()) { 129 if (buildOriginallyPublishedAt(videoInfo).getTime() > program['until'].getTime()) {
131 log.info('Video "%s" has been published after "%s", don\'t upload it.\n', 130 log.info('Video "%s" has been published after "%s", don\'t upload it.\n',
132 videoInfo.title, formatDate(program[ 'until' ])) 131 videoInfo.title, formatDate(program['until']))
133 return res() 132 return res()
134 } 133 }
135 } 134 }
@@ -174,11 +173,11 @@ function processVideo (parameters: {
174} 173}
175 174
176async function uploadVideoOnPeerTube (parameters: { 175async function uploadVideoOnPeerTube (parameters: {
177 videoInfo: any, 176 videoInfo: any
178 videoPath: string, 177 videoPath: string
179 cwd: string, 178 cwd: string
180 url: string, 179 url: string
181 user: { username: string; password: string } 180 user: { username: string, password: string }
182}) { 181}) {
183 const { videoInfo, videoPath, cwd, url, user } = parameters 182 const { videoInfo, videoPath, cwd, url, user } = parameters
184 183
@@ -206,9 +205,9 @@ async function uploadVideoOnPeerTube (parameters: {
206 205
207 const defaultAttributes = { 206 const defaultAttributes = {
208 name: truncate(videoInfo.title, { 207 name: truncate(videoInfo.title, {
209 'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max, 208 length: CONSTRAINTS_FIELDS.VIDEOS.NAME.max,
210 'separator': /,? +/, 209 separator: /,? +/,
211 'omission': ' […]' 210 omission: ' […]'
212 }), 211 }),
213 category, 212 category,
214 licence, 213 licence,
@@ -255,7 +254,7 @@ async function uploadVideoOnPeerTube (parameters: {
255async function getCategory (categories: string[], url: string) { 254async function getCategory (categories: string[], url: string) {
256 if (!categories) return undefined 255 if (!categories) return undefined
257 256
258 const categoryString = categories[ 0 ] 257 const categoryString = categories[0]
259 258
260 if (categoryString === 'News & Politics') return 11 259 if (categoryString === 'News & Politics') return 11
261 260
@@ -263,7 +262,7 @@ async function getCategory (categories: string[], url: string) {
263 const categoriesServer = res.body 262 const categoriesServer = res.body
264 263
265 for (const key of Object.keys(categoriesServer)) { 264 for (const key of Object.keys(categoriesServer)) {
266 const categoryServer = categoriesServer[ key ] 265 const categoryServer = categoriesServer[key]
267 if (categoryString.toLowerCase() === categoryServer.toLowerCase()) return parseInt(key, 10) 266 if (categoryString.toLowerCase() === categoryServer.toLowerCase()) return parseInt(key, 10)
268 } 267 }
269 268
@@ -285,12 +284,12 @@ function normalizeObject (obj: any) {
285 // Deprecated key 284 // Deprecated key
286 if (key === 'resolution') continue 285 if (key === 'resolution') continue
287 286
288 const value = obj[ key ] 287 const value = obj[key]
289 288
290 if (typeof value === 'string') { 289 if (typeof value === 'string') {
291 newObj[ key ] = value.normalize() 290 newObj[key] = value.normalize()
292 } else { 291 } else {
293 newObj[ key ] = value 292 newObj[key] = value
294 } 293 }
295 } 294 }
296 295
@@ -302,7 +301,7 @@ function fetchObject (info: any) {
302 301
303 return new Promise<any>(async (res, rej) => { 302 return new Promise<any>(async (res, rej) => {
304 const youtubeDL = await safeGetYoutubeDL() 303 const youtubeDL = await safeGetYoutubeDL()
305 youtubeDL.getInfo(url, undefined, processOptions, async (err, videoInfo) => { 304 youtubeDL.getInfo(url, undefined, processOptions, (err, videoInfo) => {
306 if (err) return rej(err) 305 if (err) return rej(err)
307 306
308 const videoInfoWithUrl = Object.assign(videoInfo, { url }) 307 const videoInfoWithUrl = Object.assign(videoInfo, { url })
@@ -313,10 +312,10 @@ function fetchObject (info: any) {
313 312
314function buildUrl (info: any) { 313function buildUrl (info: any) {
315 const webpageUrl = info.webpage_url as string 314 const webpageUrl = info.webpage_url as string
316 if (webpageUrl && webpageUrl.match(/^https?:\/\//)) return webpageUrl 315 if (webpageUrl?.match(/^https?:\/\//)) return webpageUrl
317 316
318 const url = info.url as string 317 const url = info.url as string
319 if (url && url.match(/^https?:\/\//)) return url 318 if (url?.match(/^https?:\/\//)) return url
320 319
321 // It seems youtube-dl does not return the video url 320 // It seems youtube-dl does not return the video url
322 return 'https://www.youtube.com/watch?v=' + info.id 321 return 'https://www.youtube.com/watch?v=' + info.id
@@ -384,7 +383,7 @@ function parseDate (dateAsStr: string): Date {
384} 383}
385 384
386function formatDate (date: Date): string { 385function formatDate (date: Date): string {
387 return date.toISOString().split('T')[ 0 ] 386 return date.toISOString().split('T')[0]
388} 387}
389 388
390function exitError (message: string, ...meta: any[]) { 389function exitError (message: string, ...meta: any[]) {
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts
index b341c14c1..05b75fab2 100644
--- a/server/tools/peertube-plugins.ts
+++ b/server/tools/peertube-plugins.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
@@ -79,9 +81,9 @@ async function pluginsListCLI () {
79 const plugins: PeerTubePlugin[] = res.body.data 81 const plugins: PeerTubePlugin[] = res.body.data
80 82
81 const table = new CliTable3({ 83 const table = new CliTable3({
82 head: ['name', 'version', 'homepage'], 84 head: [ 'name', 'version', 'homepage' ],
83 colWidths: [ 50, 10, 50 ] 85 colWidths: [ 50, 10, 50 ]
84 }) as CliTable3.HorizontalTable 86 }) as any
85 87
86 for (const plugin of plugins) { 88 for (const plugin of plugins) {
87 const npmName = plugin.type === PluginType.PLUGIN 89 const npmName = plugin.type === PluginType.PLUGIN
@@ -124,7 +126,6 @@ async function installPluginCLI (options: any) {
124 } catch (err) { 126 } catch (err) {
125 console.error('Cannot install plugin.', err) 127 console.error('Cannot install plugin.', err)
126 process.exit(-1) 128 process.exit(-1)
127 return
128 } 129 }
129 130
130 console.log('Plugin installed.') 131 console.log('Plugin installed.')
@@ -156,7 +157,6 @@ async function updatePluginCLI (options: any) {
156 } catch (err) { 157 } catch (err) {
157 console.error('Cannot update plugin.', err) 158 console.error('Cannot update plugin.', err)
158 process.exit(-1) 159 process.exit(-1)
159 return
160 } 160 }
161 161
162 console.log('Plugin updated.') 162 console.log('Plugin updated.')
@@ -177,12 +177,11 @@ async function uninstallPluginCLI (options: any) {
177 await uninstallPlugin({ 177 await uninstallPlugin({
178 url, 178 url,
179 accessToken, 179 accessToken,
180 npmName: options[ 'npmName' ] 180 npmName: options['npmName']
181 }) 181 })
182 } catch (err) { 182 } catch (err) {
183 console.error('Cannot uninstall plugin.', err) 183 console.error('Cannot uninstall plugin.', err)
184 process.exit(-1) 184 process.exit(-1)
185 return
186 } 185 }
187 186
188 console.log('Plugin uninstalled.') 187 console.log('Plugin uninstalled.')
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)
diff --git a/server/tools/peertube-repl.ts b/server/tools/peertube-repl.ts
index ab6e215d9..7c936ae0d 100644
--- a/server/tools/peertube-repl.ts
+++ b/server/tools/peertube-repl.ts
@@ -1,6 +1,4 @@
1import { registerTSPaths } from '../helpers/register-ts-paths' 1import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths()
3
4import * as repl from 'repl' 2import * as repl from 'repl'
5import * as path from 'path' 3import * as path from 'path'
6import * as _ from 'lodash' 4import * as _ from 'lodash'
@@ -23,6 +21,8 @@ import * as signupUtils from '../helpers/signup'
23import * as utils from '../helpers/utils' 21import * as utils from '../helpers/utils'
24import * as YoutubeDLUtils from '../helpers/youtube-dl' 22import * as YoutubeDLUtils from '../helpers/youtube-dl'
25 23
24registerTSPaths()
25
26const start = async () => { 26const start = async () => {
27 await initDatabaseModels(true) 27 await initDatabaseModels(true)
28 28
@@ -31,22 +31,39 @@ const start = async () => {
31 const initContext = (replServer) => { 31 const initContext = (replServer) => {
32 return (context) => { 32 return (context) => {
33 const properties = { 33 const properties = {
34 context, repl: replServer, env: process.env, 34 context,
35 lodash: _, path, 35 repl: replServer,
36 uuidv1, uuidv3, uuidv4, uuidv5, 36 env: process.env,
37 cli, logger, constants, 37 lodash: _,
38 Sequelize, sequelizeTypescript, modelsUtils, 38 path,
39 models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction, 39 uuidv1,
40 query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(), 40 uuidv3,
41 uuidv4,
42 uuidv5,
43 cli,
44 logger,
45 constants,
46 Sequelize,
47 sequelizeTypescript,
48 modelsUtils,
49 models: sequelizeTypescript.models,
50 transaction: sequelizeTypescript.transaction,
51 query: sequelizeTypescript.query,
52 queryInterface: sequelizeTypescript.getQueryInterface(),
41 YoutubeDL, 53 YoutubeDL,
42 coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils 54 coreUtils,
55 ffmpegUtils,
56 peertubeCryptoUtils,
57 signupUtils,
58 utils,
59 YoutubeDLUtils
43 } 60 }
44 61
45 for (let prop in properties) { 62 for (const prop in properties) {
46 Object.defineProperty(context, prop, { 63 Object.defineProperty(context, prop, {
47 configurable: false, 64 configurable: false,
48 enumerable: true, 65 enumerable: true,
49 value: properties[ prop ] 66 value: properties[prop]
50 }) 67 })
51 } 68 }
52 } 69 }
diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts
index f604c9bee..8de952e7b 100644
--- a/server/tools/peertube-upload.ts
+++ b/server/tools/peertube-upload.ts
@@ -24,14 +24,14 @@ command
24 24
25getServerCredentials(command) 25getServerCredentials(command)
26 .then(({ url, username, password }) => { 26 .then(({ url, username, password }) => {
27 if (!program[ 'videoName' ] || !program[ 'file' ]) { 27 if (!program['videoName'] || !program['file']) {
28 if (!program[ 'videoName' ]) console.error('--video-name is required.') 28 if (!program['videoName']) console.error('--video-name is required.')
29 if (!program[ 'file' ]) console.error('--file is required.') 29 if (!program['file']) console.error('--file is required.')
30 30
31 process.exit(-1) 31 process.exit(-1)
32 } 32 }
33 33
34 if (isAbsolute(program[ 'file' ]) === false) { 34 if (isAbsolute(program['file']) === false) {
35 console.error('File path should be absolute.') 35 console.error('File path should be absolute.')
36 process.exit(-1) 36 process.exit(-1)
37 } 37 }
@@ -41,25 +41,26 @@ getServerCredentials(command)
41 process.exit(-1) 41 process.exit(-1)
42 }) 42 })
43 }) 43 })
44 .catch(err => console.error(err))
44 45
45async function run (url: string, username: string, password: string) { 46async function run (url: string, username: string, password: string) {
46 const accessToken = await getAccessToken(url, username, password) 47 const accessToken = await getAccessToken(url, username, password)
47 48
48 await access(program[ 'file' ], constants.F_OK) 49 await access(program['file'], constants.F_OK)
49 50
50 console.log('Uploading %s video...', program[ 'videoName' ]) 51 console.log('Uploading %s video...', program['videoName'])
51 52
52 const videoAttributes = await buildVideoAttributesFromCommander(url, program) 53 const videoAttributes = await buildVideoAttributesFromCommander(url, program)
53 54
54 Object.assign(videoAttributes, { 55 Object.assign(videoAttributes, {
55 fixture: program[ 'file' ], 56 fixture: program['file'],
56 thumbnailfile: program[ 'thumbnail' ], 57 thumbnailfile: program['thumbnail'],
57 previewfile: program[ 'preview' ] 58 previewfile: program['preview']
58 }) 59 })
59 60
60 try { 61 try {
61 await uploadVideo(url, accessToken, videoAttributes) 62 await uploadVideo(url, accessToken, videoAttributes)
62 console.log(`Video ${program[ 'videoName' ]} uploaded.`) 63 console.log(`Video ${program['videoName']} uploaded.`)
63 process.exit(0) 64 process.exit(0)
64 } catch (err) { 65 } catch (err) {
65 console.error(require('util').inspect(err)) 66 console.error(require('util').inspect(err))
diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts
index 9ac1d05f9..5f7d1bb07 100644
--- a/server/tools/peertube-watch.ts
+++ b/server/tools/peertube-watch.ts
@@ -29,16 +29,10 @@ program
29 console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') 29 console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
30 console.log() 30 console.log()
31 }) 31 })
32 .action((url, cmd) => { 32 .action((url, cmd) => run(url, cmd))
33 run(url, cmd)
34 .catch(err => {
35 console.error(err)
36 process.exit(-1)
37 })
38 })
39 .parse(process.argv) 33 .parse(process.argv)
40 34
41async function run (url: string, program: any) { 35function run (url: string, program: any) {
42 if (!url) { 36 if (!url) {
43 console.error('<url> positional argument is required.') 37 console.error('<url> positional argument is required.')
44 process.exit(-1) 38 process.exit(-1)
diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts
index 9883bbf05..88dd5f7f6 100644
--- a/server/tools/peertube.ts
+++ b/server/tools/peertube.ts
@@ -1,13 +1,12 @@
1#!/usr/bin/env node 1#!/usr/bin/env node
2 2
3/* eslint-disable no-useless-escape */
4
3import { registerTSPaths } from '../helpers/register-ts-paths' 5import { registerTSPaths } from '../helpers/register-ts-paths'
4registerTSPaths() 6registerTSPaths()
5 7
6import * as program from 'commander' 8import * as program from 'commander'
7import { 9import { getSettings, version } from './cli'
8 version,
9 getSettings
10} from './cli'
11 10
12program 11program
13 .version(version, '-v, --version') 12 .version(version, '-v, --version')
@@ -26,14 +25,15 @@ program
26 25
27/* Not Yet Implemented */ 26/* Not Yet Implemented */
28program 27program
29 .command('diagnostic [action]', 28 .command(
30 'like couple therapy, but for your instance', 29 'diagnostic [action]',
31 { noHelp: true } as program.CommandOptions 30 'like couple therapy, but for your instance',
32 ).alias('d') 31 { noHelp: true } as program.CommandOptions
32 ).alias('d')
33 .command('admin', 33 .command('admin',
34 'manage an instance where you have elevated rights', 34 'manage an instance where you have elevated rights',
35 { noHelp: true } as program.CommandOptions 35 { noHelp: true } as program.CommandOptions
36 ).alias('a') 36 ).alias('a')
37 37
38// help on no command 38// help on no command
39if (!process.argv.slice(2).length) { 39if (!process.argv.slice(2).length) {
@@ -82,3 +82,4 @@ getSettings()
82 }) 82 })
83 .parse(process.argv) 83 .parse(process.argv)
84 }) 84 })
85 .catch(err => console.error(err))