Merge pull request #2107 from KokeroO/develop
Some checks are pending
Check Code Quality / check-lint-and-build (push) Waiting to run
Build Docker image / Build and Deploy (push) Waiting to run
Security Scan / CodeQL Analysis (javascript) (push) Waiting to run
Security Scan / Dependency Review (push) Waiting to run

fix( baileys.service ): Corrige ao salvar no DB valores Uint8Array
This commit is contained in:
Davidson Gomes 2025-10-19 17:59:26 -03:00 committed by GitHub
commit 48bda1b5af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4444,24 +4444,37 @@ export class BaileysStartupService extends ChannelStartupService {
throw new Error('Method not available in the Baileys service');
}
private convertLongToNumber(obj: any): any {
private deserializeMessageBuffers(obj: any): any {
if (obj === null || obj === undefined) {
return obj;
}
if (Long.isLong(obj)) {
return obj.toNumber();
if (typeof obj === 'object' && !Array.isArray(obj) && !Buffer.isBuffer(obj)) {
const keys = Object.keys(obj);
const isIndexedObject = keys.every((key) => !isNaN(Number(key)));
if (isIndexedObject && keys.length > 0) {
const values = keys.sort((a, b) => Number(a) - Number(b)).map((key) => obj[key]);
return new Uint8Array(values);
}
}
// Is Buffer?, converter to Uint8Array
if (Buffer.isBuffer(obj)) {
return new Uint8Array(obj);
}
// Process arrays recursively
if (Array.isArray(obj)) {
return obj.map((item) => this.convertLongToNumber(item));
return obj.map((item) => this.deserializeMessageBuffers(item));
}
// Process objects recursively
if (typeof obj === 'object') {
const converted: any = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
converted[key] = this.convertLongToNumber(obj[key]);
converted[key] = this.deserializeMessageBuffers(obj[key]);
}
}
return converted;
@ -4482,8 +4495,8 @@ export class BaileysStartupService extends ChannelStartupService {
? 'Você'
: message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)),
status: status[message.status],
message: this.convertLongToNumber({ ...message.message }),
contextInfo: this.convertLongToNumber(contentMsg?.contextInfo),
message: this.deserializeMessageBuffers({ ...message.message }),
contextInfo: this.deserializeMessageBuffers(contentMsg?.contextInfo),
messageType: contentType || 'unknown',
messageTimestamp: Long.isLong(message.messageTimestamp)
? message.messageTimestamp.toNumber()