diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 17:23:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch) | |
tree | 31a36b252df32be83ceb77658a53b57f9d15e8ac /server/tools/peertube-upload.ts | |
parent | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff) | |
download | PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip |
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'server/tools/peertube-upload.ts')
-rw-r--r-- | server/tools/peertube-upload.ts | 55 |
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 @@ | |||
1 | import * as program from 'commander' | 1 | import * as program from 'commander' |
2 | import { access, constants } from 'fs-extra' | 2 | import { access, constants } from 'fs-extra' |
3 | import { isAbsolute } from 'path' | 3 | import { isAbsolute } from 'path' |
4 | import { getClient, login } from '../../shared/extra-utils' | 4 | import { getAccessToken } from '../../shared/extra-utils' |
5 | import { uploadVideo } from '../../shared/extra-utils/' | 5 | import { uploadVideo } from '../../shared/extra-utils/' |
6 | import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getNetrc, getRemoteObjectOrDie, getSettings } from './cli' | 6 | import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getServerCredentials } from './cli' |
7 | 7 | ||
8 | let command = program | 8 | let command = program |
9 | .name('upload') | 9 | .name('upload') |
@@ -11,7 +11,6 @@ let command = program | |||
11 | command = buildCommonVideoOptions(command) | 11 | command = buildCommonVideoOptions(command) |
12 | 12 | ||
13 | command | 13 | command |
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 | ||
23 | Promise.all([ getSettings(), getNetrc() ]) | 22 | getServerCredentials(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 | ||
45 | async function run (url: string, username: string, password: string) { | 42 | async 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 | ||