mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-12 19:39:36 -06:00
Merge pull request #1897 from nolramaf/feat/validate-video-type-before-uploading-to-s3
Some checks are pending
Build Docker image / Build and Deploy (push) Waiting to run
Some checks are pending
Build Docker image / Build and Deploy (push) Waiting to run
feat/validate video type before uploading to S3
This commit is contained in:
commit
7ba878742e
@ -459,6 +459,14 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
mediaType = 'video';
|
mediaType = 'video';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
|
||||||
|
this.logger?.info?.('Video upload attempted but is disabled by configuration.');
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Video upload is currently disabled. Please contact support if you need this feature enabled.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const mimetype = result.data?.mime_type || result.headers['content-type'];
|
const mimetype = result.data?.mime_type || result.headers['content-type'];
|
||||||
|
|
||||||
const contentDisposition = result.headers['content-disposition'];
|
const contentDisposition = result.headers['content-disposition'];
|
||||||
@ -1205,8 +1213,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
const token = this.token;
|
const token = this.token;
|
||||||
|
|
||||||
const headers = { Authorization: `Bearer ${token}` };
|
const headers = { Authorization: `Bearer ${token}` };
|
||||||
const url = `${this.configService.get<WaBusiness>('WA_BUSINESS').URL}/${
|
const url = `${this.configService.get<WaBusiness>('WA_BUSINESS').URL}/${this.configService.get<WaBusiness>('WA_BUSINESS').VERSION
|
||||||
this.configService.get<WaBusiness>('WA_BUSINESS').VERSION
|
|
||||||
}/${this.number}/media`;
|
}/${this.number}/media`;
|
||||||
|
|
||||||
const res = await axios.post(url, formData, { headers });
|
const res = await axios.post(url, formData, { headers });
|
||||||
|
|||||||
@ -1205,6 +1205,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
received?.message?.ptvMessage ||
|
received?.message?.ptvMessage ||
|
||||||
received?.message?.audioMessage;
|
received?.message?.audioMessage;
|
||||||
|
|
||||||
|
const isVideo = received?.message?.videoMessage;
|
||||||
|
|
||||||
if (this.localSettings.readMessages && received.key.id !== 'status@broadcast') {
|
if (this.localSettings.readMessages && received.key.id !== 'status@broadcast') {
|
||||||
await this.client.readMessages([received.key]);
|
await this.client.readMessages([received.key]);
|
||||||
}
|
}
|
||||||
@ -1275,6 +1277,12 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (isMedia) {
|
if (isMedia) {
|
||||||
if (this.configService.get<S3>('S3').ENABLE) {
|
if (this.configService.get<S3>('S3').ENABLE) {
|
||||||
try {
|
try {
|
||||||
|
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
|
||||||
|
this.logger.warn('Video upload is disabled. Skipping video upload.');
|
||||||
|
// Skip video upload by returning early from this block
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const message: any = received;
|
const message: any = received;
|
||||||
|
|
||||||
// Verificação adicional para garantir que há conteúdo de mídia real
|
// Verificação adicional para garantir que há conteúdo de mídia real
|
||||||
@ -2168,6 +2176,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
messageSent?.message?.ptvMessage ||
|
messageSent?.message?.ptvMessage ||
|
||||||
messageSent?.message?.audioMessage;
|
messageSent?.message?.audioMessage;
|
||||||
|
|
||||||
|
const isVideo = messageSent?.message?.videoMessage;
|
||||||
|
|
||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.SEND_MESSAGE,
|
Events.SEND_MESSAGE,
|
||||||
@ -2192,6 +2202,10 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
if (isMedia && this.configService.get<S3>('S3').ENABLE) {
|
if (isMedia && this.configService.get<S3>('S3').ENABLE) {
|
||||||
try {
|
try {
|
||||||
|
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
|
||||||
|
throw new Error('Video upload is disabled.');
|
||||||
|
}
|
||||||
|
|
||||||
const message: any = messageRaw;
|
const message: any = messageRaw;
|
||||||
|
|
||||||
// Verificação adicional para garantir que há conteúdo de mídia real
|
// Verificação adicional para garantir que há conteúdo de mídia real
|
||||||
|
|||||||
@ -316,6 +316,7 @@ export type S3 = {
|
|||||||
USE_SSL?: boolean;
|
USE_SSL?: boolean;
|
||||||
REGION?: string;
|
REGION?: string;
|
||||||
SKIP_POLICY?: boolean;
|
SKIP_POLICY?: boolean;
|
||||||
|
SAVE_VIDEO?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CacheConf = { REDIS: CacheConfRedis; LOCAL: CacheConfLocal };
|
export type CacheConf = { REDIS: CacheConfRedis; LOCAL: CacheConfLocal };
|
||||||
@ -721,6 +722,7 @@ export class ConfigService {
|
|||||||
USE_SSL: process.env?.S3_USE_SSL === 'true',
|
USE_SSL: process.env?.S3_USE_SSL === 'true',
|
||||||
REGION: process.env?.S3_REGION,
|
REGION: process.env?.S3_REGION,
|
||||||
SKIP_POLICY: process.env?.S3_SKIP_POLICY === 'true',
|
SKIP_POLICY: process.env?.S3_SKIP_POLICY === 'true',
|
||||||
|
SAVE_VIDEO: process.env?.S3_SAVE_VIDEO === 'true',
|
||||||
},
|
},
|
||||||
AUTHENTICATION: {
|
AUTHENTICATION: {
|
||||||
API_KEY: {
|
API_KEY: {
|
||||||
|
|||||||
@ -3,7 +3,13 @@ import { configService, S3 } from '@config/env.config';
|
|||||||
const getTypeMessage = (msg: any) => {
|
const getTypeMessage = (msg: any) => {
|
||||||
let mediaId: string;
|
let mediaId: string;
|
||||||
|
|
||||||
if (configService.get<S3>('S3').ENABLE) mediaId = msg.message?.mediaUrl;
|
if (
|
||||||
|
configService.get<S3>('S3').ENABLE &&
|
||||||
|
(configService.get<S3>('S3').SAVE_VIDEO ||
|
||||||
|
(msg?.message?.videoMessage === undefined &&
|
||||||
|
msg?.message?.viewOnceMessageV2?.message?.videoMessage === undefined))
|
||||||
|
)
|
||||||
|
mediaId = msg.message?.mediaUrl;
|
||||||
else mediaId = msg.key?.id;
|
else mediaId = msg.key?.id;
|
||||||
|
|
||||||
const types = {
|
const types = {
|
||||||
@ -32,13 +38,11 @@ const getTypeMessage = (msg: any) => {
|
|||||||
? `videoMessage|${mediaId}${msg?.message?.videoMessage?.caption ? `|${msg?.message?.videoMessage?.caption}` : ''}`
|
? `videoMessage|${mediaId}${msg?.message?.videoMessage?.caption ? `|${msg?.message?.videoMessage?.caption}` : ''}`
|
||||||
: undefined,
|
: undefined,
|
||||||
documentMessage: msg?.message?.documentMessage
|
documentMessage: msg?.message?.documentMessage
|
||||||
? `documentMessage|${mediaId}${
|
? `documentMessage|${mediaId}${msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : ''
|
||||||
msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : ''
|
|
||||||
}`
|
}`
|
||||||
: undefined,
|
: undefined,
|
||||||
documentWithCaptionMessage: msg?.message?.documentWithCaptionMessage?.message?.documentMessage
|
documentWithCaptionMessage: msg?.message?.documentWithCaptionMessage?.message?.documentMessage
|
||||||
? `documentWithCaptionMessage|${mediaId}${
|
? `documentWithCaptionMessage|${mediaId}${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption
|
||||||
msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption
|
|
||||||
? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}`
|
? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}`
|
||||||
: ''
|
: ''
|
||||||
}`
|
}`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user