From 8704acf49efc770d73bf07c10468ed8c74d28a83 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 13 Sep 2018 14:27:44 +0200 Subject: one cli to unite them all MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ash nazg thrakatulûk agh burzum-ishi krimpatul - refactor import-videos to use the youtubeDL helper - add very basic tests for the cli --- server/tools/peertube-get-access-token.ts | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 server/tools/peertube-get-access-token.ts (limited to 'server/tools/peertube-get-access-token.ts') 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 @@ +import * as program from 'commander' + +import { + getClient, + serverLogin, + Server, + Client, + User +} from '../tests/utils/index' + +program + .option('-u, --url ', 'Server url') + .option('-n, --username ', 'Username') + .option('-p, --password ', 'Password') + .parse(process.argv) + +if ( + !program['url'] || + !program['username'] || + !program['password'] +) { + if (!program['url']) console.error('--url field is required.') + if (!program['username']) console.error('--username field is required.') + if (!program['password']) console.error('--password field is required.') + process.exit(-1) +} + +getClient(program.url) + .then(res => { + const server = { + url: program['url'], + user: { + username: program['username'], + password: program['password'] + } as User, + client: { + id: res.body.client_id as string, + secret: res.body.client_secret as string + } as Client + } as Server + + return serverLogin(server) + }) + .then(accessToken => { + console.log(accessToken) + process.exit(0) + }) + .catch(err => { + console.error(err) + process.exit(-1) + }) -- cgit v1.2.3