new(basic.gblib): HEAR in Teams will get pictures into URL.

This commit is contained in:
Rodrigo Rodriguez 2021-11-23 12:04:07 -03:00
parent ab2851fafe
commit 4368fe447b
2 changed files with 7 additions and 5 deletions

View file

@ -952,13 +952,11 @@ export class SystemKeywords {
* @example user = get "http://server/users/1" * @example user = get "http://server/users/1"
* *
*/ */
public async getByHttp(url: string, headers: any, username: string, ps: string, qs: any) { public async getByHttp(url: string, headers: any, username: string, ps: string, qs: any, streaming = false) {
let options = { let options = {
encoding: "binary", encoding: "binary",
url: url, url: url,
headers: headers headers: headers
}; };
if (username) { if (username) {
options['auth'] = { options['auth'] = {
@ -969,13 +967,17 @@ export class SystemKeywords {
if (qs) { if (qs) {
options['qs'] = qs; options['qs'] = qs;
} }
if (streaming) {
options['responseType'] = 'stream';
options['encoding'] = null;
}
const isAO = (val) => { const isAO = (val) => {
return val instanceof Array || val instanceof Object ? true : false; return val instanceof Array || val instanceof Object ? true : false;
} }
let result = await request.get(options); let result = await request.get(options);
if (isAO(result)) { if (isAO(result) && !streaming) {
GBLog.info(`[GET]: ${url} : ${result}`); GBLog.info(`[GET]: ${url} : ${result}`);
return JSON.parse(result); return JSON.parse(result);
} }

View file

@ -883,7 +883,7 @@ export class GBMinService {
const botToken = await credentials.getToken(); const botToken = await credentials.getToken();
const headers = { Authorization: `Bearer ${botToken}` }; const headers = { Authorization: `Bearer ${botToken}` };
const t = new SystemKeywords(null, null, null); const t = new SystemKeywords(null, null, null);
const data = await t.getByHttp(file.contentUrl, headers, null, null, null); const data = await t.getByHttp(file.contentUrl, headers, null, null, null, true);
const folder = `work/${min.instance.botId}.gbai/cache`; const folder = `work/${min.instance.botId}.gbai/cache`;
const filename =`${GBAdminService.generateUuid()}.png`; const filename =`${GBAdminService.generateUuid()}.png`;