From a7308ef1e838ec8cd8f3c3e86665b96f2f68cc27 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Wed, 13 Dec 2023 15:33:00 -0300 Subject: [PATCH] fix(basic.gblib): #394 UPLOAD keyword. --- .../services/KeywordsExpressions.ts | 24 +++++++++++++++ .../basic.gblib/services/SystemKeywords.ts | 29 +++++++++++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/packages/basic.gblib/services/KeywordsExpressions.ts b/packages/basic.gblib/services/KeywordsExpressions.ts index 676acde4..b9fb1c80 100644 --- a/packages/basic.gblib/services/KeywordsExpressions.ts +++ b/packages/basic.gblib/services/KeywordsExpressions.ts @@ -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++] = [ /^\s*hear (\w+\$*) as (\w+( \w+)*.xlsx)/gim, ($0, $1, $2) => { diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index 11b8b31c..c2a81461 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -30,7 +30,7 @@ | | \*****************************************************************************/ 'use strict'; -import { GBError, GBLog, GBMinInstance } from 'botlib'; +import { GBLog, GBMinInstance } from 'botlib'; import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js'; import { CollectionUtil } from 'pragmatismo-io-framework'; import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js'; @@ -68,8 +68,6 @@ import retry from 'async-retry'; import { BlobServiceClient, BlockBlobClient, - ContainerClient, - StoragePipelineOptions, StorageSharedKeyCredential } 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 { + public async uploadFile({ pid, file, data }): Promise { const { min, user } = await DialogKeywords.getProcessInfo(pid); GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`); @@ -2515,6 +2513,25 @@ 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).`); + 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 { let array = exts.filter((v, i, a) => a[i]['extension'] === ext); if (array[0]) {