new(basic.gblib): Support for saving files from GET calls.
This commit is contained in:
parent
48368beec1
commit
bad8251385
3 changed files with 698 additions and 27182 deletions
27802
package-lock.json
generated
27802
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -187,7 +187,7 @@ export class GBVMService extends GBService {
|
||||||
tolist = this.getToLst;
|
tolist = this.getToLst;
|
||||||
headers = {};
|
headers = {};
|
||||||
httpUsername = "";
|
httpUsername = "";
|
||||||
httpPassword = "";
|
httpPs = "";
|
||||||
|
|
||||||
${process.env.ENABLE_AUTH? `hear gbLogin as login`:``}
|
${process.env.ENABLE_AUTH? `hear gbLogin as login`:``}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
code = code.replace(/(\w+)\s*\=\s*get\s(.*)/gi, ($0, $1, $2) => {
|
code = code.replace(/(\w+)\s*\=\s*get\s(.*)/gi, ($0, $1, $2) => {
|
||||||
if ($2.indexOf('http') !== -1) {
|
if ($2.indexOf('http') !== -1) {
|
||||||
return `let ${$1} = sys().getByHttp (${$2}, headers, httpUsername, httpPassword)`;
|
return `let ${$1} = sys().getByHttp (${$2}, headers, httpUsername, httpPs)`;
|
||||||
} else {
|
} else {
|
||||||
return `let ${$1} = sys().get (${$2})`;
|
return `let ${$1} = sys().get (${$2})`;
|
||||||
}
|
}
|
||||||
|
@ -304,12 +304,16 @@ export class GBVMService extends GBService {
|
||||||
return `setLanguage (step, ${$3})\n`;
|
return `setLanguage (step, ${$3})\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/set http username\=\s*(.*)/gi, ($0, $1) => {
|
code = code.replace(/set header\s*(.*)\sas\s(.*)/gi, ($0, $1, $2) => {
|
||||||
|
return `headers[${$1}]=${$2})`;
|
||||||
|
});
|
||||||
|
|
||||||
|
code = code.replace(/set http username\s*\=\s*(.*)/gi, ($0, $1) => {
|
||||||
return `httpUsername = ${$1}`;
|
return `httpUsername = ${$1}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/set http password\=\s*(.*)/gi, ($0, $1) => {
|
code = code.replace(/set http password\s*\=\s*(.*)/gi, ($0, $1) => {
|
||||||
return `httpUsername = ${$1}`;
|
return `httpPs = ${$1}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/(datediff)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
|
code = code.replace(/(datediff)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
|
@ -332,10 +336,6 @@ export class GBVMService extends GBService {
|
||||||
return `setWholeWord (step, "${$3.toLowerCase()}")\n`;
|
return `setWholeWord (step, "${$3.toLowerCase()}")\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/set\s(.*)/gi, ($0, $1, $2) => {
|
|
||||||
return `sys().set (${$1})`;
|
|
||||||
});
|
|
||||||
|
|
||||||
code = code.replace(/(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gi, ($0, $1, $2, $3) => {
|
code = code.replace(/(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
return `let ${$1} = sys().httpPost (${$2}, ${$3})`;
|
return `let ${$1} = sys().httpPost (${$2}, ${$3})`;
|
||||||
});
|
});
|
||||||
|
@ -384,10 +384,18 @@ export class GBVMService extends GBService {
|
||||||
return `sys().convert(${$3})\n`;
|
return `sys().convert(${$3})\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
code = code.replace(/save\s(.*)\sas\s(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
|
return `sys().saveFile(${$2}, ${$1})\n`;
|
||||||
|
});
|
||||||
code = code.replace(/(save)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
code = code.replace(/(save)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
return `sys().save(${$3})\n`;
|
return `sys().save(${$3})\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
code = code.replace(/set\s(.*)/gi, ($0, $1, $2) => {
|
||||||
|
return `sys().set (${$1})`;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
code = `${code}\n%>`;
|
code = `${code}\n%>`;
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -87,7 +87,7 @@ export class SystemKeywords {
|
||||||
* @example SEE CAPTION OF url AS variable
|
* @example SEE CAPTION OF url AS variable
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async seeCaption(url) {
|
public async seeCaption(url) {
|
||||||
const computerVisionClient = new ComputerVisionClient(
|
const computerVisionClient = new ComputerVisionClient(
|
||||||
new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': process.env.VISION_KEY } }),
|
new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': process.env.VISION_KEY } }),
|
||||||
process.env.VISION_ENDPOINT);
|
process.env.VISION_ENDPOINT);
|
||||||
|
@ -102,7 +102,7 @@ export class SystemKeywords {
|
||||||
* @example SEE TEXT OF url AS variable
|
* @example SEE TEXT OF url AS variable
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async seeText(url) {
|
public async seeText(url) {
|
||||||
const computerVisionClient = new ComputerVisionClient(
|
const computerVisionClient = new ComputerVisionClient(
|
||||||
new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': process.env.VISION_KEY } }),
|
new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': process.env.VISION_KEY } }),
|
||||||
process.env.VISION_ENDPOINT);
|
process.env.VISION_ENDPOINT);
|
||||||
|
@ -263,6 +263,30 @@ export class SystemKeywords {
|
||||||
return documents[0];
|
return documents[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async saveFile(file: string, data: any): Promise<any> {
|
||||||
|
GBLog.info(`BASIC: Saving '${file}' (SAVE file).`);
|
||||||
|
let [baseUrl, client] = await GBDeployer.internalGetDriveClient(this.min);
|
||||||
|
const botId = this.min.instance.botId;
|
||||||
|
const path = `/${botId}.gbai/${botId}.gbdata`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client
|
||||||
|
.api(`${baseUrl}/drive/root:/${path}/${file}:/content`)
|
||||||
|
.put(data);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
if (error.code === "itemNotFound") {
|
||||||
|
GBLog.info(`BASIC: CONVERT source file not found: ${file}.`);
|
||||||
|
} else if (error.code === "nameAlreadyExists") {
|
||||||
|
GBLog.info(`BASIC: CONVERT destination file already exists: ${file}.`);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the content of several variables to a new row in a tabular file.
|
* Saves the content of several variables to a new row in a tabular file.
|
||||||
*
|
*
|
||||||
|
@ -923,16 +947,32 @@ export class SystemKeywords {
|
||||||
* @example user = get "http://server/users/1"
|
* @example user = get "http://server/users/1"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async getByHttp(url: string, headers: any, qs: any) {
|
public async getByHttp(url: string, headers: any, username: string, ps: string, qs: any) {
|
||||||
const options = {
|
const options = {
|
||||||
|
auth: {
|
||||||
|
user: username,
|
||||||
|
pass: ps
|
||||||
|
},
|
||||||
|
encoding: "binary",
|
||||||
url: url,
|
url: url,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
qs: qs,
|
qs: qs,
|
||||||
};
|
};
|
||||||
|
const isAO = (val) => {
|
||||||
|
return val instanceof Array || val instanceof Object ? true : false;
|
||||||
|
}
|
||||||
let result = await request.get(options);
|
let result = await request.get(options);
|
||||||
GBLog.info(`[GET]: ${url} : ${result}`);
|
|
||||||
return JSON.parse(result);
|
|
||||||
|
if (isAO(result)) {
|
||||||
|
GBLog.info(`[GET]: ${url} : ${result}`);
|
||||||
|
return JSON.parse(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
GBLog.info(`[GET]: OK.`);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue