diff options
author | John Livingston <git@john-livingston.fr> | 2018-05-10 23:59:28 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:23:50 +0200 |
commit | 066fc8ba71fa3573d1b1fb4c692b8f51c17111fc (patch) | |
tree | a3f2e85b76488d129ddd94e5e69579116dce4adc /server/tools/import-videos.ts | |
parent | 8be1afa12b700b93ed92365cab05c0ef81d643aa (diff) | |
download | PeerTube-066fc8ba71fa3573d1b1fb4c692b8f51c17111fc.tar.gz PeerTube-066fc8ba71fa3573d1b1fb4c692b8f51c17111fc.tar.zst PeerTube-066fc8ba71fa3573d1b1fb4c692b8f51c17111fc.zip |
import-videos: prompt for password
Diffstat (limited to 'server/tools/import-videos.ts')
-rw-r--r-- | server/tools/import-videos.ts | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/server/tools/import-videos.ts b/server/tools/import-videos.ts index f773208ab..91b897976 100644 --- a/server/tools/import-videos.ts +++ b/server/tools/import-videos.ts | |||
@@ -10,6 +10,7 @@ import { doRequestAndSaveToFile } from '../helpers/requests' | |||
10 | import { CONSTRAINTS_FIELDS } from '../initializers' | 10 | import { CONSTRAINTS_FIELDS } from '../initializers' |
11 | import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' | 11 | import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' |
12 | import { truncate } from 'lodash' | 12 | import { truncate } from 'lodash' |
13 | import * as prompt from 'prompt' | ||
13 | 14 | ||
14 | program | 15 | program |
15 | .option('-u, --url <url>', 'Server url') | 16 | .option('-u, --url <url>', 'Server url') |
@@ -23,29 +24,54 @@ program | |||
23 | if ( | 24 | if ( |
24 | !program['url'] || | 25 | !program['url'] || |
25 | !program['username'] || | 26 | !program['username'] || |
26 | !program['password'] || | ||
27 | !program['targetUrl'] | 27 | !program['targetUrl'] |
28 | ) { | 28 | ) { |
29 | console.error('All arguments are required.') | 29 | console.error('All arguments are required.') |
30 | process.exit(-1) | 30 | process.exit(-1) |
31 | } | 31 | } |
32 | 32 | ||
33 | run().catch(err => console.error(err)) | ||
34 | |||
35 | let accessToken: string | ||
36 | let client: { id: string, secret: string } | ||
37 | |||
38 | const user = { | 33 | const user = { |
39 | username: program['username'], | 34 | username: program['username'], |
40 | password: program['password'] | 35 | password: program['password'] |
41 | } | 36 | } |
42 | 37 | ||
38 | run().catch(err => console.error(err)) | ||
39 | |||
40 | let accessToken: string | ||
41 | let client: { id: string, secret: string } | ||
42 | |||
43 | const processOptions = { | 43 | const processOptions = { |
44 | cwd: __dirname, | 44 | cwd: __dirname, |
45 | maxBuffer: Infinity | 45 | maxBuffer: Infinity |
46 | } | 46 | } |
47 | 47 | ||
48 | async function promptPassword () { | ||
49 | return new Promise ( resolve => { | ||
50 | prompt.start() | ||
51 | const schema = { | ||
52 | properties: { | ||
53 | password: { | ||
54 | hidden:true, | ||
55 | required:true | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | prompt.get(schema, function(err, result) { | ||
60 | if (err) { | ||
61 | console.log(err.message) | ||
62 | } | ||
63 | resolve(result.password) | ||
64 | }) | ||
65 | }) | ||
66 | } | ||
67 | |||
48 | async function run () { | 68 | async function run () { |
69 | if ( | ||
70 | !user.password | ||
71 | ) { | ||
72 | user.password = await promptPassword(); | ||
73 | } | ||
74 | |||
49 | const res = await getClient(program['url']) | 75 | const res = await getClient(program['url']) |
50 | client = { | 76 | client = { |
51 | id: res.body.client_id, | 77 | id: res.body.client_id, |