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 { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
12 command = buildCommonVideoOptions(command)
15 .option('-u, --url <url>', 'Server url')
16 .option('-U, --username <username>', 'Username')
17 .option('-p, --password <token>', 'Password')
18 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
19 .option('-v, --preview <previewPath>', 'Preview path')
20 .option('-f, --file <file>', 'Video absolute file path')
23 const options = command.opts()
25 getServerCredentials(command)
26 .then(({ url, username, password }) => {
27 if (!options.videoName || !options.file) {
28 if (!options.videoName) console.error('--video-name is required.')
29 if (!options.file) console.error('--file is required.')
34 if (isAbsolute(options.file) === false) {
35 console.error('File path should be absolute.')
39 run(url, username, password).catch(err => {
44 .catch(err => console.error(err))
46 async function run (url: string, username: string, password: string) {
47 const server = buildServer(url)
48 await assignToken(server, username, password)
50 await access(options.file, constants.F_OK)
52 console.log('Uploading %s video...', options.videoName)
54 const baseAttributes = await buildVideoAttributesFromCommander(server, program)
59 fixture: options.file,
60 thumbnailfile: options.thumbnail,
61 previewfile: options.preview
65 await server.videosCommand.upload({ attributes })
66 console.log(`Video ${options.videoName} uploaded.`)
69 console.error(require('util').inspect(err))
74 // ----------------------------------------------------------------------------