aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/upload.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-12 12:48:58 +0100
committerChocobozzz <me@florianbigard.com>2018-02-12 12:48:58 +0100
commita87d467ad76505312fe63c597ee03a66126d0492 (patch)
tree9368de15c30c59f40fb45db7f7a60efeb4a5987b /server/tools/upload.ts
parent3df456380a3d6c7ff39b0004a5390011739ebc8e (diff)
downloadPeerTube-a87d467ad76505312fe63c597ee03a66126d0492.tar.gz
PeerTube-a87d467ad76505312fe63c597ee03a66126d0492.tar.zst
PeerTube-a87d467ad76505312fe63c597ee03a66126d0492.zip
Fix upload from CLI script
Diffstat (limited to 'server/tools/upload.ts')
-rw-r--r--server/tools/upload.ts101
1 files changed, 52 insertions, 49 deletions
diff --git a/server/tools/upload.ts b/server/tools/upload.ts
index db59bbdff..3bf9dd65e 100644
--- a/server/tools/upload.ts
+++ b/server/tools/upload.ts
@@ -2,84 +2,87 @@ import * as program from 'commander'
2import { access, constants } from 'fs' 2import { access, constants } from 'fs'
3import { isAbsolute } from 'path' 3import { isAbsolute } from 'path'
4import { promisify } from 'util' 4import { promisify } from 'util'
5import { getClient, login } from '../tests/utils'
6import { uploadVideo } from '../tests/utils/index'
5 7
6const accessPromise = promisify(access) 8const accessPromise = promisify(access)
7 9
8import { uploadVideo } from '../tests/utils/index'
9
10program 10program
11 .option('-u, --url <url>', 'Server url') 11 .option('-u, --url <url>', 'Server url')
12 .option('-a, --access-token <token>', 'Access token') 12 .option('-U, --username <username>', 'Username')
13 .option('-n, --name <name>', 'Video name') 13 .option('-p, --password <token>', 'Password')
14 .option('-n, --video-name <name>', 'Video name')
14 .option('-N, --nsfw', 'Video is Not Safe For Work') 15 .option('-N, --nsfw', 'Video is Not Safe For Work')
15 .option('-c, --category <category number>', 'Category number') 16 .option('-c, --category <category number>', 'Category number')
17 .option('-m, --comments-enabled', 'Enable comments')
16 .option('-l, --licence <licence number>', 'Licence number') 18 .option('-l, --licence <licence number>', 'Licence number')
17 .option('-L, --language <language number>', 'Language number') 19 .option('-L, --language <language number>', 'Language number')
18 .option('-d, --description <description>', 'Video description') 20 .option('-d, --video-description <description>', 'Video description')
19 .option('-t, --tags <tags>', 'Video tags', list) 21 .option('-t, --tags <tags>', 'Video tags', list)
20 .option('-f, --file <file>', 'Video absolute file path') 22 .option('-f, --file <file>', 'Video absolute file path')
21 .parse(process.argv) 23 .parse(process.argv)
22 24
23if (!program['tags']) program['tags'] = [] 25if (!program['tags']) program['tags'] = []
24if (!program['nsfw']) program['nsfw'] = false 26if (!program['nsfw']) program['nsfw'] = false
27if (!program['commentsEnabled']) program['commentsEnabled'] = false
25 28
26if ( 29if (
27 !program['url'] || 30 !program['url'] ||
28 !program['accessToken'] || 31 !program['username'] ||
29 !program['name'] || 32 !program['password'] ||
30 !program['category'] || 33 !program['videoName'] ||
31 !program['licence'] ||
32 !program['description'] ||
33 !program['file'] 34 !program['file']
34) { 35) {
35 throw new Error('All arguments but tags, language and nsfw are required.') 36 console.error('Url, username, password, name and input file are required.')
37 process.exit(-1)
36} 38}
37 39
38if (isAbsolute(program['file']) === false) { 40if (isAbsolute(program['file']) === false) {
39 throw new Error('File path should be absolute.') 41 console.error('File path should be absolute.')
42 process.exit(-1)
40} 43}
41 44
42accessPromise(program['file'], constants.F_OK) 45run().catch(err => console.error(err))
43 .then(() => {
44 return upload(
45 program['url'],
46 program['accessToken'],
47 program['name'],
48 program['category'],
49 program['licence'],
50 program['language'],
51 program['nsfw'],
52 program['description'],
53 program['tags'],
54 program['file']
55 )
56 })
57 .then(() => process.exit(0))
58 .catch(err => {
59 console.error(err)
60 process.exit(-1)
61 })
62 46
63// ---------------------------------------------------------------------------- 47async function run () {
48 const res = await getClient(program[ 'url' ])
49 const client = {
50 id: res.body.client_id,
51 secret: res.body.client_secret
52 }
64 53
65function list (val) { 54 const user = {
66 return val.split(',') 55 username: program[ 'username' ],
67} 56 password: program[ 'password' ]
57 }
58
59 const res2 = await login(program[ 'url' ], client, user)
60 const accessToken = res2.body.access_token
68 61
69function upload (url, accessToken, name, category, licence, language, nsfw, description, tags, fixture) { 62 await accessPromise(program[ 'file' ], constants.F_OK)
70 console.log('Uploading %s video...', program['name']) 63
64 console.log('Uploading %s video...', program[ 'videoName' ])
71 65
72 const videoAttributes = { 66 const videoAttributes = {
73 name, 67 name: program['videoName'],
74 category, 68 category: program['category'],
75 licence, 69 licence: program['licence'],
76 language, 70 language: program['language'],
77 nsfw, 71 nsfw: program['nsfw'],
78 description, 72 description: program['videoDescription'],
79 tags, 73 tags: program['tags'],
80 fixture 74 commentsEnabled: program['commentsEnabled'],
75 fixture: program['file']
81 } 76 }
82 return uploadVideo(url, accessToken, videoAttributes).then(() => { 77
83 console.log(`Video ${name} uploaded.`) 78 await uploadVideo(program['url'], accessToken, videoAttributes)
84 }) 79
80 console.log(`Video ${program['videoName']} uploaded.`)
81 process.exit(0)
82}
83
84// ----------------------------------------------------------------------------
85
86function list (val) {
87 return val.split(',')
85} 88}