fix(basic.gblib): #394 UPLOAD keyword.
This commit is contained in:
parent
df7300a68c
commit
57bb89a73e
3 changed files with 22 additions and 15 deletions
|
@ -540,7 +540,7 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
};
|
||||
|
||||
// Transfers NLP auto variables into global object.
|
||||
// Transfers auto variables into global object.
|
||||
|
||||
for(i in this.variables) {
|
||||
global[i] = this.variables[i];
|
||||
|
@ -933,7 +933,7 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
}
|
||||
|
||||
// Adds params as variables to be added later as global objects..
|
||||
// Adds params as variables to be added later as global objects.
|
||||
|
||||
keys = Object.keys(params);
|
||||
for (let j = 0; j < keys.length; j++) {
|
||||
|
|
|
@ -420,8 +420,8 @@ 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}})`;
|
||||
const params = this.getParams($4, ['remotePath']);
|
||||
return `${$1} = await sys.dirFolder ({pid: pid, ${params}})`;
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -435,8 +435,8 @@ export class KeywordsExpressions {
|
|||
|
||||
keywords[i++] = [
|
||||
/^\s*(.*)\=\s*(UPLOAD)(\s*)(.*)/gim,
|
||||
($0, $1, $2, $3) => {
|
||||
const params = this.getParams($3, ['file']);
|
||||
($0, $1, $2, $3, $4) => {
|
||||
const params = this.getParams($4, ['file']);
|
||||
return `await sys.uploadFile ({pid: pid, ${params}})`;
|
||||
}
|
||||
];
|
||||
|
|
|
@ -656,18 +656,13 @@ export class SystemKeywords {
|
|||
* @exaple UPLOAD file.
|
||||
*
|
||||
*/
|
||||
public async uploadFile({ pid, file, data }): Promise<any> {
|
||||
public async uploadFile({ pid, file }): Promise<any> {
|
||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||
GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`);
|
||||
|
||||
// Checks if it is a GB FILE object.
|
||||
|
||||
if (data.data && data.filename) {
|
||||
data = data.data;
|
||||
}
|
||||
|
||||
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');
|
||||
|
@ -681,11 +676,23 @@ export class SystemKeywords {
|
|||
`${baseUrl}`,
|
||||
sharedKeyCredential
|
||||
);
|
||||
|
||||
|
||||
let data;
|
||||
|
||||
// It is an SharePoint object that needs to be downloaded.
|
||||
|
||||
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||
const localName = Path.join('work', gbaiName, 'cache', `${GBAdminService.getRndReadableIdentifier()}.tmp`);
|
||||
const url = file['url'];
|
||||
const response = await fetch(url);
|
||||
Fs.writeFileSync(localName, Buffer.from(await response.arrayBuffer()), { encoding: null });
|
||||
|
||||
const container = blobServiceClient.getContainerClient(accountName);
|
||||
const hash = new Uint8Array(md5.array(data));
|
||||
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
|
||||
|
||||
const res = await blockBlobClient.uploadFile(data.filename,
|
||||
const res = await blockBlobClient.uploadFile(localName,
|
||||
{
|
||||
blobHTTPHeaders: {
|
||||
blobContentMD5: hash
|
||||
|
@ -693,8 +700,7 @@ export class SystemKeywords {
|
|||
});
|
||||
|
||||
if (res._response.status === 200 && res.contentMD5 === hash) {
|
||||
const tmpFile = '';
|
||||
Fs.rmSync(tmpFile);
|
||||
Fs.rmSync(localName);
|
||||
}
|
||||
else {
|
||||
GBLog.error(`BASIC: BLOB HTTP ${res.errorCode} ${res._response.status} .`);
|
||||
|
@ -2613,6 +2619,7 @@ export class SystemKeywords {
|
|||
obj['size'] = item.size;
|
||||
obj['hash'] = item.file?.hashes?.quickXorHash;
|
||||
obj['path'] = Path.join(remotePath, item.name);
|
||||
obj['url'] = item['@microsoft.graph.downloadUrl'];
|
||||
|
||||
array.push(obj);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue