mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 20:22:54 -06:00
refactor: add validation for media content in Evolution and Business services to enhance error handling
This commit is contained in:
parent
8ea4d65bc2
commit
1a1d9fc957
@ -455,6 +455,12 @@ export class EvolutionStartupService extends ChannelStartupService {
|
|||||||
if (base64 || file || audioFile) {
|
if (base64 || file || audioFile) {
|
||||||
if (this.configService.get<S3>('S3').ENABLE) {
|
if (this.configService.get<S3>('S3').ENABLE) {
|
||||||
try {
|
try {
|
||||||
|
// Verificação adicional para garantir que há conteúdo de mídia real
|
||||||
|
const hasRealMedia = this.hasValidMediaContent(messageRaw);
|
||||||
|
|
||||||
|
if (!hasRealMedia) {
|
||||||
|
this.logger.warn('Message detected as media but contains no valid media content');
|
||||||
|
} else {
|
||||||
const fileBuffer = audioFile?.buffer || file?.buffer;
|
const fileBuffer = audioFile?.buffer || file?.buffer;
|
||||||
const buffer = base64 ? Buffer.from(base64, 'base64') : fileBuffer;
|
const buffer = base64 ? Buffer.from(base64, 'base64') : fileBuffer;
|
||||||
|
|
||||||
@ -488,6 +494,7 @@ export class EvolutionStartupService extends ChannelStartupService {
|
|||||||
const mediaUrl = await s3Service.getObjectUrl(fullName);
|
const mediaUrl = await s3Service.getObjectUrl(fullName);
|
||||||
|
|
||||||
messageRaw.message.mediaUrl = mediaUrl;
|
messageRaw.message.mediaUrl = mediaUrl;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
|
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
|
||||||
}
|
}
|
||||||
|
@ -429,6 +429,12 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
try {
|
try {
|
||||||
const message: any = received;
|
const message: any = received;
|
||||||
|
|
||||||
|
// Verificação adicional para garantir que há conteúdo de mídia real
|
||||||
|
const hasRealMedia = this.hasValidMediaContent(messageRaw);
|
||||||
|
|
||||||
|
if (!hasRealMedia) {
|
||||||
|
this.logger.warn('Message detected as media but contains no valid media content');
|
||||||
|
} else {
|
||||||
const id = message.messages[0][message.messages[0].type].id;
|
const id = message.messages[0][message.messages[0].type].id;
|
||||||
let urlServer = this.configService.get<WaBusiness>('WA_BUSINESS').URL;
|
let urlServer = this.configService.get<WaBusiness>('WA_BUSINESS').URL;
|
||||||
const version = this.configService.get<WaBusiness>('WA_BUSINESS').VERSION;
|
const version = this.configService.get<WaBusiness>('WA_BUSINESS').VERSION;
|
||||||
@ -533,6 +539,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
|
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user