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) {
|
for(i in this.variables) {
|
||||||
global[i] = this.variables[i];
|
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);
|
keys = Object.keys(params);
|
||||||
for (let j = 0; j < keys.length; j++) {
|
for (let j = 0; j < keys.length; j++) {
|
||||||
|
|
|
@ -420,8 +420,8 @@ export class KeywordsExpressions {
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(.*)\=\s*(DIR)(\s*)(.*)/gim,
|
/^\s*(.*)\=\s*(DIR)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3, $4) => {
|
($0, $1, $2, $3, $4) => {
|
||||||
const params = this.getParams($4, ['path']);
|
const params = this.getParams($4, ['remotePath']);
|
||||||
return `await sys.dirFolder ({pid: pid, ${params}})`;
|
return `${$1} = await sys.dirFolder ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -435,8 +435,8 @@ export class KeywordsExpressions {
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(.*)\=\s*(UPLOAD)(\s*)(.*)/gim,
|
/^\s*(.*)\=\s*(UPLOAD)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3, $4) => {
|
||||||
const params = this.getParams($3, ['file']);
|
const params = this.getParams($4, ['file']);
|
||||||
return `await sys.uploadFile ({pid: pid, ${params}})`;
|
return `await sys.uploadFile ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -656,18 +656,13 @@ export class SystemKeywords {
|
||||||
* @exaple UPLOAD file.
|
* @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);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`);
|
GBLog.info(`BASIC: Saving Blob'${file}' (SAVE file).`);
|
||||||
|
|
||||||
// Checks if it is a GB FILE object.
|
// Checks if it is a GB FILE object.
|
||||||
|
|
||||||
if (data.data && data.filename) {
|
|
||||||
data = data.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = GBServer.globals.files[data].data;
|
|
||||||
const accountName = min.getParam('Blob Account');
|
const accountName = min.getParam('Blob Account');
|
||||||
const accountKey = min.getParam('Blob Key');
|
const accountKey = min.getParam('Blob Key');
|
||||||
const blobName = min.getParam('Blob Name');
|
const blobName = min.getParam('Blob Name');
|
||||||
|
@ -681,11 +676,23 @@ export class SystemKeywords {
|
||||||
`${baseUrl}`,
|
`${baseUrl}`,
|
||||||
sharedKeyCredential
|
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 container = blobServiceClient.getContainerClient(accountName);
|
||||||
const hash = new Uint8Array(md5.array(data));
|
const hash = new Uint8Array(md5.array(data));
|
||||||
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
|
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
|
||||||
|
|
||||||
const res = await blockBlobClient.uploadFile(data.filename,
|
const res = await blockBlobClient.uploadFile(localName,
|
||||||
{
|
{
|
||||||
blobHTTPHeaders: {
|
blobHTTPHeaders: {
|
||||||
blobContentMD5: hash
|
blobContentMD5: hash
|
||||||
|
@ -693,8 +700,7 @@ export class SystemKeywords {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res._response.status === 200 && res.contentMD5 === hash) {
|
if (res._response.status === 200 && res.contentMD5 === hash) {
|
||||||
const tmpFile = '';
|
Fs.rmSync(localName);
|
||||||
Fs.rmSync(tmpFile);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GBLog.error(`BASIC: BLOB HTTP ${res.errorCode} ${res._response.status} .`);
|
GBLog.error(`BASIC: BLOB HTTP ${res.errorCode} ${res._response.status} .`);
|
||||||
|
@ -2613,6 +2619,7 @@ export class SystemKeywords {
|
||||||
obj['size'] = item.size;
|
obj['size'] = item.size;
|
||||||
obj['hash'] = item.file?.hashes?.quickXorHash;
|
obj['hash'] = item.file?.hashes?.quickXorHash;
|
||||||
obj['path'] = Path.join(remotePath, item.name);
|
obj['path'] = Path.join(remotePath, item.name);
|
||||||
|
obj['url'] = item['@microsoft.graph.downloadUrl'];
|
||||||
|
|
||||||
array.push(obj);
|
array.push(obj);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue