fix(basic.gblib): #395 TALK with no quotes.

This commit is contained in:
Rodrigo Rodriguez 2023-12-19 07:16:20 -03:00
parent 825d6c1a0f
commit 872471c13f
3 changed files with 62 additions and 58 deletions

View file

@ -434,7 +434,7 @@ export class KeywordsExpressions {
/^\s*(.*)\=\s*(UPLOAD)(\s*)(.*)/gim,
($0, $1, $2, $3, $4) => {
const params = this.getParams($4, ['file']);
return `await sys.uploadFile ({pid: pid, ${params}})`;
return `${$1} = await sys.uploadFile ({pid: pid, ${params}})`;
}
];
@ -909,13 +909,14 @@ export class KeywordsExpressions {
keywords[i++] = [
/^\s*(talk)(\s*)(.*)/gim,
($0, $1, $2, $3) => {
$3 = GBVMService.normalizeQuotes($3);
// Issue: #395
// $3 = GBVMService.normalizeQuotes($3);
// Uses auto quote if this is a frase with more then one word.
// // Uses auto quote if this is a phrase with more then one word.
if (/\s/.test($3) && $3.substr(0, 1) !== '"') {
$3 = `"${$3}"`;
}
// if (/\s/.test($3) && $3.substr(0, 1) !== '`') {
// $3 = "`" + $3 + "`";
// }
return `await dk.talk ({pid: pid, text: ${$3}})`;
}
];

View file

@ -664,7 +664,7 @@ export class SystemKeywords {
const accountName = min.core.getParam(min.instance, 'Blob Account');
const accountKey = min.core.getParam(min.instance, 'Blob Key');
const blobName = min.core.getParam(min.instance, 'Blob Name');
const sharedKeyCredential = new StorageSharedKeyCredential(
accountName,
accountKey
@ -693,7 +693,7 @@ export class SystemKeywords {
// Performs uploading passing local hash.
const container = blobServiceClient.getContainerClient(accountName);
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(file.path);
const res = await blockBlobClient.uploadFile(localName,
{
blobHTTPHeaders: {
@ -703,10 +703,11 @@ export class SystemKeywords {
// If upload is OK including hash check, removes the temporary file.
if ((res._response.status === 200 || res._response.status === 201) && res.contentMD5 === hash) {
if (res._response.status === 201 &&
(new Uint8Array(res.contentMD5)).toString() === hash.toString()) {
Fs.rmSync(localName);
file['md5'] = res.contentMD5;
file['md5'] = hash.toString();
return file;
@ -2546,20 +2547,20 @@ export class SystemKeywords {
return { contentType, ext, kind, category: kind['category'] };
}
private async deleteFile({ min, file }) {
// const file = GBServer.globals.files[handle];
GBLog.info(`BASIC: Auto saving '${file.filename}' (SAVE file).`);
public async deleteFile({ pid, file }) {
const { min } = await DialogKeywords.getProcessInfo(pid);
GBLog.info(`BASIC: DELETE '${file.name}'.`);
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
const fileName = file.url ? file.url : file.name;
const gbaiPath = DialogKeywords.getGBAIPath(min.botId);
const fileName = file.name;
const contentType = mime.lookup(fileName);
const ext = Path.extname(fileName).substring(1);
const kind = await this.getExtensionInfo(ext);
const result = await client
.api(`${baseUrl}/drive/root:/${path}/${file}`)
.delete(file.data);
await client
.api(`${baseUrl}/drive/root:/${gbaiPath}/${file.path}`)
.delete();
return { contentType, ext, kind, category: kind['category'] };
}
@ -2576,7 +2577,7 @@ export class SystemKeywords {
/**
* Loads all para from tabular file Config.xlsx.
*/
public async dirFolder({ pid, remotePath, baseUrl = null, array = null }) {
public async dirFolder({ pid, remotePath, baseUrl = null, client = null, array = null }) {
const { min } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min, `dirFolder: remotePath=${remotePath}, baseUrl=${baseUrl}`);
@ -2585,9 +2586,11 @@ export class SystemKeywords {
array = [];
}
if (!baseUrl) {
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
if (!baseUrl){
let obj = await GBDeployer.internalGetDriveClient(min);
baseUrl = obj.baseUrl;
client = obj.client;
}
remotePath = remotePath.replace(/\\/gi, '/');
@ -2610,7 +2613,8 @@ export class SystemKeywords {
if (item.folder) {
remotePath = urlJoin(remotePath, item.name);
array = [array, ... await this.dirFolder({ pid, remotePath, baseUrl, array })];
array = [...array, ... await this.dirFolder({ pid, remotePath, baseUrl, client, array })];
} else {
// TODO: https://raw.githubusercontent.com/ishanarora04/quickxorhash/master/quickxorhash.js
@ -2629,5 +2633,4 @@ export class SystemKeywords {
return array;
}
}
}

View file

@ -123,7 +123,7 @@ export class GBDeployer implements IGBDeployer {
const baseUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}`;
min['cacheToken'] = { baseUrl, client };
return min['cacheToken'];
return { baseUrl, client };
}