2019-10-21 17:13:07 +02:00
|
|
|
import { registerTSPaths } from '../helpers/register-ts-paths'
|
|
|
|
registerTSPaths()
|
|
|
|
|
2021-06-25 17:48:27 +02:00
|
|
|
import { program } from 'commander'
|
2018-08-27 13:28:49 +02:00
|
|
|
import { access, constants } from 'fs-extra'
|
2017-09-07 17:58:09 +02:00
|
|
|
import { isAbsolute } from 'path'
|
2019-04-15 15:26:15 +02:00
|
|
|
import { uploadVideo } from '../../shared/extra-utils/'
|
2021-07-13 11:44:16 +02:00
|
|
|
import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
|
2017-09-07 17:58:09 +02:00
|
|
|
|
2019-06-13 13:53:28 +02:00
|
|
|
let command = program
|
2018-09-13 14:27:44 +02:00
|
|
|
.name('upload')
|
2019-06-13 13:53:28 +02:00
|
|
|
|
|
|
|
command = buildCommonVideoOptions(command)
|
|
|
|
|
|
|
|
command
|
2017-09-07 17:58:09 +02:00
|
|
|
.option('-u, --url <url>', 'Server url')
|
2018-02-12 12:48:58 +01:00
|
|
|
.option('-U, --username <username>', 'Username')
|
|
|
|
.option('-p, --password <token>', 'Password')
|
2018-02-15 14:46:26 +01:00
|
|
|
.option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
|
2018-02-15 18:40:24 +01:00
|
|
|
.option('-v, --preview <previewPath>', 'Preview path')
|
2017-09-07 17:58:09 +02:00
|
|
|
.option('-f, --file <file>', 'Video absolute file path')
|
|
|
|
.parse(process.argv)
|
|
|
|
|
2021-02-03 09:33:05 +01:00
|
|
|
const options = command.opts()
|
|
|
|
|
2019-07-11 17:23:24 +02:00
|
|
|
getServerCredentials(command)
|
|
|
|
.then(({ url, username, password }) => {
|
2021-02-03 09:33:05 +01:00
|
|
|
if (!options.videoName || !options.file) {
|
|
|
|
if (!options.videoName) console.error('--video-name is required.')
|
|
|
|
if (!options.file) console.error('--file is required.')
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2019-07-11 17:23:24 +02:00
|
|
|
process.exit(-1)
|
|
|
|
}
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2021-02-03 09:33:05 +01:00
|
|
|
if (isAbsolute(options.file) === false) {
|
2019-07-11 17:23:24 +02:00
|
|
|
console.error('File path should be absolute.')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2019-07-11 17:23:24 +02:00
|
|
|
run(url, username, password).catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(-1)
|
|
|
|
})
|
|
|
|
})
|
2020-01-31 16:56:52 +01:00
|
|
|
.catch(err => console.error(err))
|
2017-09-07 17:58:09 +02:00
|
|
|
|
2019-04-25 13:55:28 +02:00
|
|
|
async function run (url: string, username: string, password: string) {
|
2021-07-13 11:44:16 +02:00
|
|
|
const server = buildServer(url)
|
|
|
|
await assignToken(server, username, password)
|
2017-09-07 17:58:09 +02:00
|
|
|
|
2021-02-03 09:33:05 +01:00
|
|
|
await access(options.file, constants.F_OK)
|
2018-02-12 12:48:58 +01:00
|
|
|
|
2021-02-03 09:33:05 +01:00
|
|
|
console.log('Uploading %s video...', options.videoName)
|
2017-09-07 17:58:09 +02:00
|
|
|
|
2021-07-09 15:03:44 +02:00
|
|
|
const videoAttributes = await buildVideoAttributesFromCommander(server, program)
|
2019-06-13 13:53:28 +02:00
|
|
|
|
|
|
|
Object.assign(videoAttributes, {
|
2021-02-03 09:33:05 +01:00
|
|
|
fixture: options.file,
|
|
|
|
thumbnailfile: options.thumbnail,
|
|
|
|
previewfile: options.preview
|
2019-06-13 13:53:28 +02:00
|
|
|
})
|
2018-02-12 12:48:58 +01:00
|
|
|
|
2019-04-25 13:55:28 +02:00
|
|
|
try {
|
2021-07-13 11:44:16 +02:00
|
|
|
await uploadVideo(url, server.accessToken, videoAttributes)
|
2021-02-03 09:33:05 +01:00
|
|
|
console.log(`Video ${options.videoName} uploaded.`)
|
2019-04-25 13:55:28 +02:00
|
|
|
process.exit(0)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(require('util').inspect(err))
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
2018-02-12 12:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|