-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat/validate video type before uploading to S3 #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/validate video type before uploading to S3 #1897
Conversation
Reviewer's GuideThis PR introduces a new SAVE_VIDEO flag to the S3 configuration and updates message handling and upload paths to detect and skip video uploads when this flag is disabled, along with minor formatting cleanups. Sequence diagram for video upload validation before S3 uploadsequenceDiagram
participant Service as BaileysStartupService/BusinessStartupService
participant Config as ConfigService
participant S3 as S3
participant S3Bucket as S3 Bucket
Service->>Config: get<S3>("S3")
Config-->>Service: S3 config (ENABLE, SAVE_VIDEO)
Service->>Service: Check if message is video
alt SAVE_VIDEO is false and message is video
Service->>Service: Throw error 'Video upload is disabled.'
else SAVE_VIDEO is true or not video
Service->>S3Bucket: Upload media
end
Class diagram for updated S3 configuration and message handlingclassDiagram
class ConfigService {
+get<S3>(key: string): S3
...
}
class S3 {
ENABLE: boolean
SAVE_VIDEO: boolean
...
}
ConfigService --> S3
class BaileysStartupService {
+handleReceivedMessage(received)
+handleSentMessage(messageSent)
...
}
BaileysStartupService --> ConfigService
class BusinessStartupService {
+uploadMedia(result)
...
}
BusinessStartupService --> ConfigService
class getTypeMessage {
+getTypeMessage(msg)
}
getTypeMessage --> ConfigService
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The
if (isVideo && !SAVE_VIDEO)block is repeated in multiple places; consider extracting that logic into a shared helper or middleware to DRY up the upload flow. - The conditional logic in getConversationMessage around SAVE_VIDEO and media types is becoming complex—refactor or simplify it into smaller functions for readability and easier maintenance.
- Instead of throwing a generic Error when video uploads are disabled, use a custom error class or error code so downstream logic can handle this case more explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `if (isVideo && !SAVE_VIDEO)` block is repeated in multiple places; consider extracting that logic into a shared helper or middleware to DRY up the upload flow.
- The conditional logic in getConversationMessage around SAVE_VIDEO and media types is becoming complex—refactor or simplify it into smaller functions for readability and easier maintenance.
- Instead of throwing a generic Error when video uploads are disabled, use a custom error class or error code so downstream logic can handle this case more explicitly.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:1263` </location>
<code_context>
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.');
+ }
+
</code_context>
<issue_to_address>
Throwing an error for disabled video upload may disrupt flow.
Instead of raising an exception, consider skipping video uploads and logging a warning to prevent service interruption for other media types.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
=======
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;
}
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `src/api/integrations/channel/meta/whatsapp.business.service.ts:462` </location>
<code_context>
mediaType = 'video';
}
+ if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
+ throw new Error('Video upload is disabled.');
+ }
+
</code_context>
<issue_to_address>
Error thrown for disabled video upload may affect user experience.
Instead of raising an exception, consider returning a user-friendly message or logging the event to avoid disrupting the user experience.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
=======
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.',
};
}
>>>>>>> REPLACE
</suggested_fix>
### Comment 3
<location> `src/config/env.config.ts:285` </location>
<code_context>
USE_SSL?: boolean;
REGION?: string;
SKIP_POLICY?: boolean;
+ SAVE_VIDEO: boolean;
};
</code_context>
<issue_to_address>
SAVE_VIDEO type should be optional for consistency.
Marking SAVE_VIDEO as optional aligns with the other S3 config properties and helps prevent issues with undefined values.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
SAVE_VIDEO: boolean;
=======
SAVE_VIDEO?: boolean;
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
|
Please fix the lint with |
Summary by Sourcery
Introduce a new SAVE_VIDEO configuration flag to prevent unnecessary S3 uploads for video messages when disabled, and enforce this check across message handling services and utilities.
New Features:
Enhancements: