]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/real-world/tools/upload.js
Add link to wiki for production installation
[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('-x, --nsfw', 'Video is Not Safe For Work')
13 .option('-c, --category <category number>', 'Category number')
14 .option('-l, --licence <licence number>', 'Licence number')
15 .option('-d, --description <description>', 'Video description')
16 .option('-t, --tags <tags>', 'Video tags', list)
17 .option('-f, --file <file>', 'Video absolute file path')
18 .parse(process.argv)
19
20 if (
21 !program.url ||
22 !program.accessToken ||
23 !program.name ||
24 !program.category ||
25 !program.licence ||
26 !program.nsfw ||
27 !program.description ||
28 !program.tags ||
29 !Array.isArray(program.tags) ||
30 program.tags.length === 0 ||
31 !program.file
32 ) {
33 throw new Error('All arguments are required.')
34 }
35
36 fs.access(program.file, fs.F_OK, function (err) {
37 if (err) throw err
38
39 upload(
40 program.url,
41 program.accessToken,
42 program.name,
43 program.category,
44 program.licence,
45 program.nsfw,
46 program.description,
47 program.tags,
48 program.file
49 )
50 })
51
52 // ----------------------------------------------------------------------------
53
54 function list (val) {
55 return val.split(',')
56 }
57
58 function upload (url, accessToken, name, category, licence, nsfw, description, tags, fixture) {
59 console.log('Uploading %s video...', program.name)
60
61 const videoAttributes = {
62 name,
63 category,
64 licence,
65 nsfw,
66 description,
67 tags,
68 fixture
69 }
70 utils.uploadVideo(url, accessToken, videoAttributes, function (err) {
71 if (err) throw err
72
73 console.log('Video uploaded.')
74 })
75 }