feat(SystemKeywords): integrate MinIO client for file retrieval in gbcluster mode
Some checks failed
GBCI / build (push) Failing after 4m47s
Some checks failed
GBCI / build (push) Failing after 4m47s
This commit is contained in:
parent
d2851aabd6
commit
eb9ddb7ead
2 changed files with 39 additions and 4 deletions
|
@ -73,6 +73,7 @@ import { Page } from 'facebook-nodejs-business-sdk';
|
||||||
|
|
||||||
import { md5 } from 'js-md5';
|
import { md5 } from 'js-md5';
|
||||||
import { GBUtil } from '../../../src/util.js';
|
import { GBUtil } from '../../../src/util.js';
|
||||||
|
import { Client } from 'minio';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview General Bots server core.
|
* @fileoverview General Bots server core.
|
||||||
|
@ -1175,8 +1176,44 @@ export class SystemKeywords {
|
||||||
} else if (file.indexOf('.csv') !== -1) {
|
} else if (file.indexOf('.csv') !== -1) {
|
||||||
let res;
|
let res;
|
||||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbdata`);
|
let packagePath = GBUtil.getGBAIPath(min.botId, `gbdata`);
|
||||||
|
|
||||||
|
if (GBConfigService.get('GB_MODE') === 'gbcluster') {
|
||||||
|
|
||||||
|
const fileUrl = urlJoin('/', `${min.botId}.gbdata`, file);
|
||||||
|
GBLogEx.info(min, `Direct data from .csv: ${fileUrl}.`);
|
||||||
|
|
||||||
|
const fileOnly = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
|
const minioClient = new Client({
|
||||||
|
endPoint: process.env.DRIVE_SERVER || 'localhost',
|
||||||
|
port: parseInt(process.env.DRIVE_PORT || '9000', 10),
|
||||||
|
useSSL: process.env.DRIVE_USE_SSL === 'true',
|
||||||
|
accessKey: process.env.DRIVE_ACCESSKEY,
|
||||||
|
secretKey: process.env.DRIVE_SECRET,
|
||||||
|
});
|
||||||
|
|
||||||
|
const bucketName = (process.env.DRIVE_ORG_PREFIX + min.botId + '.gbai').toLowerCase();
|
||||||
|
const localName = path.join(
|
||||||
|
'work',
|
||||||
|
gbaiName,
|
||||||
|
'cache',
|
||||||
|
`${fileOnly.replace(/\s/gi, '')}-${GBAdminService.getNumberIdentifier()}.${ext}`
|
||||||
|
);
|
||||||
|
|
||||||
|
await minioClient.fGetObject(bucketName, fileUrl, localName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const csvFile = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, file);
|
const csvFile = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, file);
|
||||||
const data = await fs.readFile(csvFile, 'utf8');
|
const data = await fs.readFile(csvFile, 'utf8');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const firstLine = data.split('\n')[0];
|
const firstLine = data.split('\n')[0];
|
||||||
const headers = firstLine.split(',');
|
const headers = firstLine.split(',');
|
||||||
const db = await csvdb(csvFile, headers, ',');
|
const db = await csvdb(csvFile, headers, ',');
|
||||||
|
|
|
@ -465,7 +465,6 @@ export class GBMinService {
|
||||||
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
|
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
|
||||||
|
|
||||||
const challenge = (min.core['getParam'] as any)(min.instance, `Meta Challenge`, null, true);
|
const challenge = (min.core['getParam'] as any)(min.instance, `Meta Challenge`, null, true);
|
||||||
GBLogEx.info(min, `Meta callback entering...${challenge} ${JSON.stringify(req.query)}`);
|
|
||||||
|
|
||||||
const status = req.body?.entry?.[0]?.changes?.[0]?.value?.statuses?.[0];
|
const status = req.body?.entry?.[0]?.changes?.[0]?.value?.statuses?.[0];
|
||||||
|
|
||||||
|
@ -481,7 +480,6 @@ export class GBMinService {
|
||||||
if (challenge && val === challenge) {
|
if (challenge && val === challenge) {
|
||||||
res.send(req.query['hub.challenge']);
|
res.send(req.query['hub.challenge']);
|
||||||
res.status(200);
|
res.status(200);
|
||||||
GBLogEx.info(min, `Meta callback OK. ${JSON.stringify(req.query)}`);
|
|
||||||
} else {
|
} else {
|
||||||
res.status(401);
|
res.status(401);
|
||||||
}
|
}
|
||||||
|
@ -1096,7 +1094,7 @@ export class GBMinService {
|
||||||
GBMinService.pidsConversation[conversationId] = pid;
|
GBMinService.pidsConversation[conversationId] = pid;
|
||||||
step.context.activity['pid'] = pid;
|
step.context.activity['pid'] = pid;
|
||||||
|
|
||||||
const auth = min.core.getParam(min.instance, 'Enable Authentication', null);
|
const auth = true; // min.core.getParam(min.instance, 'Enable Authentication', null);
|
||||||
|
|
||||||
if (auth) {
|
if (auth) {
|
||||||
const res = await t.find({ pid: pid, handle: "users.csv", args: [`key={member.id}`] });
|
const res = await t.find({ pid: pid, handle: "users.csv", args: [`key={member.id}`] });
|
||||||
|
|
Loading…
Add table
Reference in a new issue