]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/real-world/tools/upload.js
Server: fix update remote video infohash
[github/Chocobozzz/PeerTube.git] / server / tests / real-world / tools / upload.js
1 'use strict'
2
3 const program = require('commander')
4 const fs = require('fs')
5
6 const utils = require('../../utils/videos')
7
8 program
9 .option('-u, --url <url>', 'Server url')
10 .option('-a, --access-token <token>', 'Access token')
11 .option('-n, --name <name>', 'Video name')
12 .option('-d, --description <description>', 'Video description')
13 .option('-t, --tags <tags>', 'Video tags', list)
14 .option('-f, --file <file>', 'Video absolute file path')
15 .parse(process.argv)
16
17 if (
18 !program.url ||
19 !program.accessToken ||
20 !program.name ||
21 !program.description ||
22 !program.tags ||
23 !Array.isArray(program.tags) ||
24 program.tags.length === 0 ||
25 !program.file
26 ) {
27 throw new Error('All arguments are required.')
28 }
29
30 fs.access(program.file, fs.F_OK, function (err) {
31 if (err) throw err
32
33 upload(
34 program.url,
35 program.accessToken,
36 program.name,
37 program.description,
38 program.tags,
39 program.file
40 )
41 })
42
43 // ----------------------------------------------------------------------------
44
45 function list (val) {
46 return val.split(',')
47 }
48
49 function upload (url, accessToken, name, description, tags, file) {
50 console.log('Uploading %s video...', program.name)
51
52 utils.uploadVideo(url, accessToken, name, description, tags, file, function (err) {
53 if (err) throw err
54
55 console.log('Video uploaded.')
56 })
57 }