fix(basic.gblib): #394 UPLOAD keyword.

This commit is contained in:
Rodrigo Rodriguez 2023-12-13 15:33:00 -03:00
parent bd3fd5d6af
commit a7308ef1e8
2 changed files with 47 additions and 6 deletions

View file

@ -418,6 +418,30 @@ export class KeywordsExpressions {
} }
]; ];
keywords[i++] = [
/^\s*(.*)\=\s*(DIR)(\s*)(.*)/gim,
($0, $1, $2, $3, $4) => {
const params = this.getParams($4, ['path']);
return `await sys.dirFolder ({pid: pid, ${params}})`;
}
];
keywords[i++] = [
/^\s*(DELETE)(\s*)(.*)/gim,
($0, $1, $2, $3, $4) => {
const params = this.getParams($4, ['file']);
return `await sys.deleteFile ({pid: pid, ${params}})`;
}
];
keywords[i++] = [
/^\s*(.*)\=\s*(UPLOAD)(\s*)(.*)/gim,
($0, $1, $2, $3, $4) => {
const params = this.getParams($4, ['file']);
return `await sys.uploadFile ({pid: pid, ${params}})`;
}
];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+\$*) as (\w+( \w+)*.xlsx)/gim, /^\s*hear (\w+\$*) as (\w+( \w+)*.xlsx)/gim,
($0, $1, $2) => { ($0, $1, $2) => {

View file

@ -30,7 +30,7 @@
| | | |
\*****************************************************************************/ \*****************************************************************************/
'use strict'; 'use strict';
import { GBError, GBLog, GBMinInstance } from 'botlib'; import { GBLog, GBMinInstance } from 'botlib';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js'; import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
import { CollectionUtil } from 'pragmatismo-io-framework'; import { CollectionUtil } from 'pragmatismo-io-framework';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js'; import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
@ -68,8 +68,6 @@ import retry from 'async-retry';
import { import {
BlobServiceClient, BlobServiceClient,
BlockBlobClient, BlockBlobClient,
ContainerClient,
StoragePipelineOptions,
StorageSharedKeyCredential StorageSharedKeyCredential
} from '@azure/storage-blob'; } from '@azure/storage-blob';
@ -653,12 +651,12 @@ export class SystemKeywords {
} }
/** /**
* Saves the content of variable into the file in .gbdata default folder. * Saves the content of variable into BLOB storage.
* *
* @exaple SAVE file AS "blob/my.txt" * @exaple UPLOAD file.
* *
*/ */
public async saveBlob({ pid, file, data }): Promise<any> { public async uploadFile({ pid, file, data }): Promise<any> {
const { min, user } = await DialogKeywords.getProcessInfo(pid); const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`); GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`);
@ -2515,6 +2513,25 @@ export class SystemKeywords {
return { contentType, ext, kind, category: kind['category'] }; 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).`);
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
const fileName = file.url ? file.url : 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);
return { contentType, ext, kind, category: kind['category'] };
}
public async getExtensionInfo(ext: any): Promise<any> { public async getExtensionInfo(ext: any): Promise<any> {
let array = exts.filter((v, i, a) => a[i]['extension'] === ext); let array = exts.filter((v, i, a) => a[i]['extension'] === ext);
if (array[0]) { if (array[0]) {