From 066fc8ba71fa3573d1b1fb4c692b8f51c17111fc Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 10 May 2018 23:59:28 +0200 Subject: import-videos: prompt for password --- server/tools/import-videos.ts | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'server/tools') 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' import { CONSTRAINTS_FIELDS } from '../initializers' import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' import { truncate } from 'lodash' +import * as prompt from 'prompt' program .option('-u, --url ', 'Server url') @@ -23,29 +24,54 @@ program if ( !program['url'] || !program['username'] || - !program['password'] || !program['targetUrl'] ) { console.error('All arguments are required.') process.exit(-1) } -run().catch(err => console.error(err)) - -let accessToken: string -let client: { id: string, secret: string } - const user = { username: program['username'], password: program['password'] } +run().catch(err => console.error(err)) + +let accessToken: string +let client: { id: string, secret: string } + const processOptions = { cwd: __dirname, maxBuffer: Infinity } +async function promptPassword () { + return new Promise ( resolve => { + prompt.start() + const schema = { + properties: { + password: { + hidden:true, + required:true + } + } + } + prompt.get(schema, function(err, result) { + if (err) { + console.log(err.message) + } + resolve(result.password) + }) + }) +} + async function run () { + if ( + !user.password + ) { + user.password = await promptPassword(); + } + const res = await getClient(program['url']) client = { id: res.body.client_id, -- cgit v1.2.3