diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-07-20 19:16:00 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-07-20 19:16:00 +0200 |
commit | 677618d4a600a1678088d107850c8f1f8c95255f (patch) | |
tree | b0ea636094a7a6c8188757bcd2a68ce1231e3d6f /server/tests/real-world/tools/upload.js | |
parent | 2bd3f171270aff9717a55f2b89757fe966911af3 (diff) | |
download | PeerTube-677618d4a600a1678088d107850c8f1f8c95255f.tar.gz PeerTube-677618d4a600a1678088d107850c8f1f8c95255f.tar.zst PeerTube-677618d4a600a1678088d107850c8f1f8c95255f.zip |
Server: Add some cli tools to make it easy to upload a lot of videos
Diffstat (limited to 'server/tests/real-world/tools/upload.js')
-rw-r--r-- | server/tests/real-world/tools/upload.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/server/tests/real-world/tools/upload.js b/server/tests/real-world/tools/upload.js new file mode 100644 index 000000000..39b4c9b40 --- /dev/null +++ b/server/tests/real-world/tools/upload.js | |||
@@ -0,0 +1,57 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const program = require('commander') | ||
4 | const fs = require('fs') | ||
5 | |||
6 | const utils = require('../../api/utils') | ||
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 | } | ||