1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

accept requestJson for create/edit as stdin

This commit is contained in:
Kyle Spearrin
2018-05-16 22:40:48 -04:00
parent 9cce555899
commit 07cb4d5ff8
5 changed files with 66 additions and 33 deletions

View File

@@ -3,29 +3,16 @@ import * as program from 'commander';
import { Response } from '../models/response';
import { StringResponse } from '../models/response/stringResponse';
export class EncodeCommand {
run(cmd: program.Command): Promise<Response> {
if (process.stdin == null || process.stdin.isTTY) {
return Promise.resolve(Response.badRequest('No stdin was piped in.'));
}
import { CliUtils } from '../utils';
return new Promise((resolve, reject) => {
let input: string = '';
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
while (true) {
const chunk = process.stdin.read();
if (chunk == null) {
break;
}
input += chunk;
}
});
process.stdin.on('end', () => {
const b64 = new Buffer(input, 'utf8').toString('base64');
const res = new StringResponse(b64);
resolve(Response.success(res));
});
});
export class EncodeCommand {
async run(cmd: program.Command): Promise<Response> {
if (process.stdin.isTTY) {
return Response.badRequest('No stdin was piped in.');
}
const input = await CliUtils.readStdin();
const b64 = new Buffer(input, 'utf8').toString('base64');
const res = new StringResponse(b64);
return Response.success(res);
}
}