new(core.gbapp): Save to Azure Blob.
This commit is contained in:
parent
46265b31d5
commit
4b4205a599
2 changed files with 69 additions and 0 deletions
|
@ -64,6 +64,7 @@
|
||||||
"@azure/ms-rest-js": "2.6.2",
|
"@azure/ms-rest-js": "2.6.2",
|
||||||
"@azure/msal-node": "1.14.3",
|
"@azure/msal-node": "1.14.3",
|
||||||
"@azure/search-documents": "11.3.1",
|
"@azure/search-documents": "11.3.1",
|
||||||
|
"@azure/storage-blob": "12.17.0",
|
||||||
"@google-cloud/pubsub": "3.2.1",
|
"@google-cloud/pubsub": "3.2.1",
|
||||||
"@google-cloud/translate": "7.0.4",
|
"@google-cloud/translate": "7.0.4",
|
||||||
"@hubspot/api-client": "7.1.2",
|
"@hubspot/api-client": "7.1.2",
|
||||||
|
@ -119,6 +120,7 @@
|
||||||
"googleapis": "109.0.1",
|
"googleapis": "109.0.1",
|
||||||
"ibm-watson": "7.1.2",
|
"ibm-watson": "7.1.2",
|
||||||
"join-images-updated": "1.1.4",
|
"join-images-updated": "1.1.4",
|
||||||
|
"js-md5": "0.8.3",
|
||||||
"keyv": "4.5.2",
|
"keyv": "4.5.2",
|
||||||
"koa": "2.13.4",
|
"koa": "2.13.4",
|
||||||
"koa-body": "6.0.1",
|
"koa-body": "6.0.1",
|
||||||
|
|
|
@ -65,6 +65,14 @@ import exts from '../../../extensions.json' assert { type: 'json' };
|
||||||
import { SecService } from '../../security.gbapp/services/SecService.js';
|
import { SecService } from '../../security.gbapp/services/SecService.js';
|
||||||
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
||||||
import retry from 'async-retry';
|
import retry from 'async-retry';
|
||||||
|
import {
|
||||||
|
BlobServiceClient,
|
||||||
|
BlockBlobClient,
|
||||||
|
ContainerClient,
|
||||||
|
StoragePipelineOptions
|
||||||
|
} from '@azure/storage-blob';
|
||||||
|
|
||||||
|
import { md5 } from 'js-md5';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview General Bots server core.
|
* @fileoverview General Bots server core.
|
||||||
|
@ -643,6 +651,63 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the content of variable into the file in .gbdata default folder.
|
||||||
|
*
|
||||||
|
* @exaple SAVE file AS "blob/my.txt"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public async saveBlob({ pid, file, data }): Promise<any> {
|
||||||
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`);
|
||||||
|
|
||||||
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
|
||||||
|
// Checks if it is a GB FILE object.
|
||||||
|
|
||||||
|
if (data.data && data.filename) {
|
||||||
|
data = data.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
data = GBServer.globals.files[data].data;
|
||||||
|
|
||||||
|
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 container = client.getContainerClient(containerName);
|
||||||
|
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
|
||||||
|
|
||||||
|
const hash = new Uint8Array(md5.array(data));
|
||||||
|
|
||||||
|
await blockBlobClient.uploadFile(data.filename,
|
||||||
|
{blobHTTPHeaders:{
|
||||||
|
blobContentMD5:hash}});
|
||||||
|
|
||||||
|
const tmpFile = '';
|
||||||
|
await blockBlobClient.downloadToFile(tmpFile);
|
||||||
|
|
||||||
|
Fs.rmSync(tmpFile);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'itemNotFound') {
|
||||||
|
GBLog.info(`BASIC: BASIC source file not found: ${file}.`);
|
||||||
|
} else if (error.code === 'nameAlreadyExists') {
|
||||||
|
GBLog.info(`BASIC: BASIC destination file already exists: ${file}.`);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes note inside a notes.xlsx of .gbdata.
|
* Takes note inside a notes.xlsx of .gbdata.
|
||||||
*
|
*
|
||||||
|
@ -2452,4 +2517,6 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
return { category: 'Other', description: 'General documents' };
|
return { category: 'Other', description: 'General documents' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue