aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-upload.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-upload.ts')
-rw-r--r--server/tools/peertube-upload.ts55
1 files changed, 19 insertions, 36 deletions
diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts
index c00205e8f..d9f9a8ead 100644
--- a/server/tools/peertube-upload.ts
+++ b/server/tools/peertube-upload.ts
@@ -1,9 +1,9 @@
1import * as program from 'commander' 1import * as program from 'commander'
2import { access, constants } from 'fs-extra' 2import { access, constants } from 'fs-extra'
3import { isAbsolute } from 'path' 3import { isAbsolute } from 'path'
4import { getClient, login } from '../../shared/extra-utils' 4import { getAccessToken } from '../../shared/extra-utils'
5import { uploadVideo } from '../../shared/extra-utils/' 5import { uploadVideo } from '../../shared/extra-utils/'
6import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getNetrc, getRemoteObjectOrDie, getSettings } from './cli' 6import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
7 7
8let command = program 8let command = program
9 .name('upload') 9 .name('upload')
@@ -11,7 +11,6 @@ let command = program
11command = buildCommonVideoOptions(command) 11command = buildCommonVideoOptions(command)
12 12
13command 13command
14
15 .option('-u, --url <url>', 'Server url') 14 .option('-u, --url <url>', 'Server url')
16 .option('-U, --username <username>', 'Username') 15 .option('-U, --username <username>', 'Username')
17 .option('-p, --password <token>', 'Password') 16 .option('-p, --password <token>', 'Password')
@@ -20,44 +19,28 @@ command
20 .option('-f, --file <file>', 'Video absolute file path') 19 .option('-f, --file <file>', 'Video absolute file path')
21 .parse(process.argv) 20 .parse(process.argv)
22 21
23Promise.all([ getSettings(), getNetrc() ]) 22getServerCredentials(command)
24 .then(([ settings, netrc ]) => { 23 .then(({ url, username, password }) => {
25 const { url, username, password } = getRemoteObjectOrDie(program, settings, netrc) 24 if (!program[ 'videoName' ] || !program[ 'file' ]) {
26 25 if (!program[ 'videoName' ]) console.error('--video-name is required.')
27 if (!program[ 'videoName' ] || !program[ 'file' ]) { 26 if (!program[ 'file' ]) console.error('--file is required.')
28 if (!program[ 'videoName' ]) console.error('--video-name is required.')
29 if (!program[ 'file' ]) console.error('--file is required.')
30 27
31 process.exit(-1) 28 process.exit(-1)
32 } 29 }
33 30
34 if (isAbsolute(program[ 'file' ]) === false) { 31 if (isAbsolute(program[ 'file' ]) === false) {
35 console.error('File path should be absolute.') 32 console.error('File path should be absolute.')
36 process.exit(-1) 33 process.exit(-1)
37 } 34 }
38 35
39 run(url, username, password).catch(err => { 36 run(url, username, password).catch(err => {
40 console.error(err) 37 console.error(err)
41 process.exit(-1) 38 process.exit(-1)
42 }) 39 })
43 }) 40 })
44 41
45async function run (url: string, username: string, password: string) { 42async function run (url: string, username: string, password: string) {
46 const resClient = await getClient(url) 43 const accessToken = await getAccessToken(url, username, password)
47 const client = {
48 id: resClient.body.client_id,
49 secret: resClient.body.client_secret
50 }
51
52 const user = { username, password }
53
54 let accessToken: string
55 try {
56 const res = await login(url, client, user)
57 accessToken = res.body.access_token
58 } catch (err) {
59 throw new Error('Cannot authenticate. Please check your username/password.')
60 }
61 44
62 await access(program[ 'file' ], constants.F_OK) 45 await access(program[ 'file' ], constants.F_OK)
63 46