diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-09-13 14:27:44 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2018-09-14 11:08:55 +0200 |
commit | 8704acf49efc770d73bf07c10468ed8c74d28a83 (patch) | |
tree | ffd46289fcf9a13ac4412b167e9f71dfb35753c5 /server/tools/peertube-get-access-token.ts | |
parent | 1d9d9cfdcf3983e3fd89026bc4b5633a8abf5752 (diff) | |
download | PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.gz PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.zst PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.zip |
one cli to unite them all
Ash nazg thrakatulûk agh burzum-ishi krimpatul
- refactor import-videos to use the youtubeDL helper
- add very basic tests for the cli
Diffstat (limited to 'server/tools/peertube-get-access-token.ts')
-rw-r--r-- | server/tools/peertube-get-access-token.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/server/tools/peertube-get-access-token.ts b/server/tools/peertube-get-access-token.ts new file mode 100644 index 000000000..eb2571a03 --- /dev/null +++ b/server/tools/peertube-get-access-token.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | import * as program from 'commander' | ||
2 | |||
3 | import { | ||
4 | getClient, | ||
5 | serverLogin, | ||
6 | Server, | ||
7 | Client, | ||
8 | User | ||
9 | } from '../tests/utils/index' | ||
10 | |||
11 | program | ||
12 | .option('-u, --url <url>', 'Server url') | ||
13 | .option('-n, --username <username>', 'Username') | ||
14 | .option('-p, --password <token>', 'Password') | ||
15 | .parse(process.argv) | ||
16 | |||
17 | if ( | ||
18 | !program['url'] || | ||
19 | !program['username'] || | ||
20 | !program['password'] | ||
21 | ) { | ||
22 | if (!program['url']) console.error('--url field is required.') | ||
23 | if (!program['username']) console.error('--username field is required.') | ||
24 | if (!program['password']) console.error('--password field is required.') | ||
25 | process.exit(-1) | ||
26 | } | ||
27 | |||
28 | getClient(program.url) | ||
29 | .then(res => { | ||
30 | const server = { | ||
31 | url: program['url'], | ||
32 | user: { | ||
33 | username: program['username'], | ||
34 | password: program['password'] | ||
35 | } as User, | ||
36 | client: { | ||
37 | id: res.body.client_id as string, | ||
38 | secret: res.body.client_secret as string | ||
39 | } as Client | ||
40 | } as Server | ||
41 | |||
42 | return serverLogin(server) | ||
43 | }) | ||
44 | .then(accessToken => { | ||
45 | console.log(accessToken) | ||
46 | process.exit(0) | ||
47 | }) | ||
48 | .catch(err => { | ||
49 | console.error(err) | ||
50 | process.exit(-1) | ||
51 | }) | ||