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

This commit is contained in:
Rodrigo Rodriguez 2023-12-12 23:47:19 -03:00
parent 3fa89851d2
commit 10871af6ca

View file

@ -69,7 +69,8 @@ import {
BlobServiceClient,
BlockBlobClient,
ContainerClient,
StoragePipelineOptions
StoragePipelineOptions,
StorageSharedKeyCredential
} from '@azure/storage-blob';
import { md5 } from 'js-md5';
@ -672,29 +673,37 @@ export class SystemKeywords {
try {
data = GBServer.globals.files[data].data;
const accountName = min.getParam('Blob Account');
const accountKey = min.getParam('Blob Key');
const blobName = min.getParam('Blob Name');
const connString = min.getParam('Blob ConnectionString');
const containerName = min.getParam('Blob Container Name');
const storagePipelineOptions: StoragePipelineOptions = {};
const client: BlobServiceClient = BlobServiceClient.fromConnectionString(
connString,
storagePipelineOptions
const sharedKeyCredential = new StorageSharedKeyCredential(
accountName,
accountKey
);
const container = client.getContainerClient(containerName);
const baseUrl = `https://${accountName}.blob.core.windows.net`;
const blobServiceClient = new BlobServiceClient(
`${baseUrl}`,
sharedKeyCredential
);
const container = blobServiceClient.getContainerClient(accountName);
const hash = new Uint8Array(md5.array(data));
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
const hash = new Uint8Array(md5.array(data));
await blockBlobClient.uploadFile(data.filename,
{blobHTTPHeaders:{
blobContentMD5:hash}});
const res = await blockBlobClient.uploadFile(data.filename,
{
blobHTTPHeaders: {
blobContentMD5: hash
}
});
if (res._response.status===200 && res.contentMD5 === hash) {
const tmpFile = '';
await blockBlobClient.downloadToFile(tmpFile);
Fs.rmSync(tmpFile);
}
else{
GBLog.error(`BASIC: BLOB HTTP ${res.errorCode} ${res._response.status} .`);
}
} catch (error) {
@ -1659,7 +1668,7 @@ export class SystemKeywords {
return res;
}
public async getCustomToken({pid, token}) :Promise<string>{
public async getCustomToken({ pid, token }): Promise<string> {
const { min } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min, `GET TOKEN: ${token}`);
@ -2361,8 +2370,8 @@ export class SystemKeywords {
// In case of storage, persist to DB in batch.
if (fieldsValuesList.length){
await this.saveToStorageBatch({ pid, table: file, rows:fieldsValuesList });
if (fieldsValuesList.length) {
await this.saveToStorageBatch({ pid, table: file, rows: fieldsValuesList });
}
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}).`);