feat(SystemKeywords): integrate MinIO client for file retrieval in gbcluster mode
Some checks failed
GBCI / build (push) Failing after 4m47s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-04-17 15:05:09 -03:00
parent d2851aabd6
commit eb9ddb7ead
2 changed files with 39 additions and 4 deletions

View file

@ -73,6 +73,7 @@ import { Page } from 'facebook-nodejs-business-sdk';
import { md5 } from 'js-md5';
import { GBUtil } from '../../../src/util.js';
import { Client } from 'minio';
/**
* @fileoverview General Bots server core.
@ -1175,8 +1176,44 @@ export class SystemKeywords {
} else if (file.indexOf('.csv') !== -1) {
let res;
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 data = await fs.readFile(csvFile, 'utf8');
const firstLine = data.split('\n')[0];
const headers = firstLine.split(',');
const db = await csvdb(csvFile, headers, ',');

View file

@ -465,7 +465,6 @@ export class GBMinService {
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
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];
@ -481,7 +480,6 @@ export class GBMinService {
if (challenge && val === challenge) {
res.send(req.query['hub.challenge']);
res.status(200);
GBLogEx.info(min, `Meta callback OK. ${JSON.stringify(req.query)}`);
} else {
res.status(401);
}
@ -1096,7 +1094,7 @@ export class GBMinService {
GBMinService.pidsConversation[conversationId] = 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) {
const res = await t.find({ pid: pid, handle: "users.csv", args: [`key={member.id}`] });