1 import { registerTSPaths } from '../helpers/register-ts-paths'
4 import { program } from 'commander'
5 import { access, constants } from 'fs-extra'
6 import { isAbsolute } from 'path'
7 import { uploadVideo } from '../../shared/extra-utils/'
8 import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
13 command = buildCommonVideoOptions(command)
16 .option('-u, --url <url>', 'Server url')
17 .option('-U, --username <username>', 'Username')
18 .option('-p, --password <token>', 'Password')
19 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
20 .option('-v, --preview <previewPath>', 'Preview path')
21 .option('-f, --file <file>', 'Video absolute file path')
24 const options = command.opts()
26 getServerCredentials(command)
27 .then(({ url, username, password }) => {
28 if (!options.videoName || !options.file) {
29 if (!options.videoName) console.error('--video-name is required.')
30 if (!options.file) console.error('--file is required.')
35 if (isAbsolute(options.file) === false) {
36 console.error('File path should be absolute.')
40 run(url, username, password).catch(err => {
45 .catch(err => console.error(err))
47 async function run (url: string, username: string, password: string) {
48 const server = buildServer(url)
49 await assignToken(server, username, password)
51 await access(options.file, constants.F_OK)
53 console.log('Uploading %s video...', options.videoName)
55 const videoAttributes = await buildVideoAttributesFromCommander(server, program)
57 Object.assign(videoAttributes, {
58 fixture: options.file,
59 thumbnailfile: options.thumbnail,
60 previewfile: options.preview
64 await uploadVideo(url, server.accessToken, videoAttributes)
65 console.log(`Video ${options.videoName} uploaded.`)
68 console.error(require('util').inspect(err))
73 // ----------------------------------------------------------------------------