UNPKG

wechaty-puppet-padplus

Version:
61 lines 2.77 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const aws_sdk_1 = __importDefault(require("aws-sdk")); const config_1 = require("../../config"); const PRE = 'REQUEST'; class RequestClient { constructor(grpcGateway, emitter) { this.grpcGateway = grpcGateway; this.emitter = emitter; } request(option) { return __awaiter(this, void 0, void 0, function* () { config_1.log.silly(PRE, `request()`); const uin = this.emitter.getUIN(); const res = yield this.grpcGateway.request(option.apiType, uin, option.data); return res; }); } uploadFile(filename, stream) { return __awaiter(this, void 0, void 0, function* () { filename = decodeURIComponent(filename); let params = { ACL: 'public-read', Body: stream, Bucket: config_1.AWS_S3.BUCKET, Key: config_1.AWS_S3.PATH + filename, }; aws_sdk_1.default.config.accessKeyId = config_1.AWS_S3.ACCESS_KEY_ID; aws_sdk_1.default.config.secretAccessKey = config_1.AWS_S3.SECRET_ACCESS_KEY; const s3 = new aws_sdk_1.default.S3({ region: 'cn-northwest-1', signatureVersion: 'v4' }); const result = yield new Promise((resolve, reject) => { s3.upload(params, (err, data) => { if (err) { reject(err); } else { config_1.log.silly(PRE, `data : ${JSON.stringify(data)}`); resolve(data); } }); }); const location = result.Location; const _location = location.split('image-message')[0] + params.Key; return _location; }); } } exports.RequestClient = RequestClient; //# sourceMappingURL=request.js.map