feat/validate video type before uploading to S3

This commit is contained in:
Marlon Alves
2025-09-01 19:41:56 -03:00
parent 9cdb897a0f
commit 293f655274
4 changed files with 43 additions and 22 deletions

View File

@@ -459,6 +459,10 @@ export class BusinessStartupService extends ChannelStartupService {
mediaType = 'video';
}
if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
const mimetype = result.data?.mime_type || result.headers['content-type'];
const contentDisposition = result.headers['content-disposition'];
@@ -1205,9 +1209,8 @@ export class BusinessStartupService extends ChannelStartupService {
const token = this.token;
const headers = { Authorization: `Bearer ${token}` };
const url = `${this.configService.get<WaBusiness>('WA_BUSINESS').URL}/${
this.configService.get<WaBusiness>('WA_BUSINESS').VERSION
}/${this.number}/media`;
const url = `${this.configService.get<WaBusiness>('WA_BUSINESS').URL}/${this.configService.get<WaBusiness>('WA_BUSINESS').VERSION
}/${this.number}/media`;
const res = await axios.post(url, formData, { headers });
return res.data.id;

View File

@@ -368,7 +368,7 @@ export class BaileysStartupService extends ChannelStartupService {
qrcodeTerminal.generate(qr, { small: true }, (qrcode) =>
this.logger.log(
`\n{ instance: ${this.instance.name} pairingCode: ${this.instance.qrcode.pairingCode}, qrcodeCount: ${this.instance.qrcode.count} }\n` +
qrcode,
qrcode,
),
);
@@ -961,16 +961,16 @@ export class BaileysStartupService extends ChannelStartupService {
const messagesRepository: Set<string> = new Set(
chatwootImport.getRepositoryMessagesCache(instance) ??
(
await this.prismaRepository.message.findMany({
select: { key: true },
where: { instanceId: this.instanceId },
})
).map((message) => {
const key = message.key as { id: string };
(
await this.prismaRepository.message.findMany({
select: { key: true },
where: { instanceId: this.instanceId },
})
).map((message) => {
const key = message.key as { id: string };
return key.id;
}),
return key.id;
}),
);
if (chatwootImport.getRepositoryMessagesCache(instance) === null) {
@@ -1188,6 +1188,8 @@ export class BaileysStartupService extends ChannelStartupService {
received?.message?.ptvMessage ||
received?.message?.audioMessage;
const isVideo = received?.message?.videoMessage;
if (this.localSettings.readMessages && received.key.id !== 'status@broadcast') {
await this.client.readMessages([received.key]);
}
@@ -1258,6 +1260,10 @@ export class BaileysStartupService extends ChannelStartupService {
if (isMedia) {
if (this.configService.get<S3>('S3').ENABLE) {
try {
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
const message: any = received;
// Verificação adicional para garantir que há conteúdo de mídia real
@@ -2143,6 +2149,8 @@ export class BaileysStartupService extends ChannelStartupService {
messageSent?.message?.ptvMessage ||
messageSent?.message?.audioMessage;
const isVideo = messageSent?.message?.videoMessage;
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
this.chatwootService.eventWhatsapp(
Events.SEND_MESSAGE,
@@ -2167,6 +2175,10 @@ export class BaileysStartupService extends ChannelStartupService {
if (isMedia && this.configService.get<S3>('S3').ENABLE) {
try {
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
const message: any = messageRaw;
// Verificação adicional para garantir que há conteúdo de mídia real