| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
All images sent via the Baileys integration are now pre-processed and converted to JPEG format using the `sharp` library. This ensures better compatibility and prevents potential issues with unsupported formats. - Images from URLs are now downloaded via axios before processing, which allows for the use of a proxy. - The default filename and mimetype are updated to `image.jpg` and `image/jpeg` to reflect the conversion.
Reviewer's GuideIntroduces an image preprocessing pipeline in the Baileys WhatsApp service: images are downloaded or decoded, converted to JPEG via sharp (with optional proxy support), default filename and mimetype updated to .jpg/jpeg, and the mediaInput is unified in the prepareWAMessageMedia call. Sequence diagram for image preprocessing and sending in WhatsApp Baileys integrationsequenceDiagram
participant Service as BaileysStartupService
participant Proxy as Proxy (optional)
participant Axios as axios
participant Sharp as sharp
participant WA as WhatsApp API
Service->>Axios: Download image from URL (with proxy if enabled)
Axios-->>Service: Return image buffer
Service->>Sharp: Convert image buffer to JPEG
Sharp-->>Service: Return JPEG buffer
Service->>WA: Send JPEG image with updated filename/mimetype
Class diagram for BaileysStartupService image handling changesclassDiagram
class BaileysStartupService {
+localProxy
+client
+sendMediaMessage(mediaMessage)
}
class mediaMessage {
+mediatype
+media
+fileName
+mimetype
}
BaileysStartupService --> mediaMessage : uses
class ProxyConfig {
+host
+port
+protocol
+username
+password
}
BaileysStartupService --> ProxyConfig : uses (if enabled)
class sharp {
+jpeg()
+toBuffer()
}
BaileysStartupService --> sharp : converts image to JPEG
class axios {
+get(url, config)
}
BaileysStartupService --> axios : downloads image
class prepareWAMessageMedia {
+upload
}
BaileysStartupService --> prepareWAMessageMedia : prepares media for WhatsApp
File-Level Changes
Tips and commands Interacting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sorry, something went wrong.
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI AgentsPlease address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2470` </location>
<code_context>
+ };
+ }
+
+ const response = await axios.get(mediaMessage.media, config);
+ imageBuffer = Buffer.from(response.data, 'binary');
+ } else {
</code_context>
<issue_to_address>
Network errors from axios.get are not explicitly handled.
Catch errors from axios.get to prevent unhandled promise rejections when the image URL is unreachable or returns a non-200 status.
</issue_to_address>
### Comment 2
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2477` </location>
<code_context>
+ }
+
+ mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
+ mediaMessage.fileName ??= 'image.jpg';
+ mediaMessage.mimetype = 'image/jpeg';
+ } else {
</code_context>
<issue_to_address>
Redundant fileName assignment logic exists below.
Consolidate the fileName assignment to a single location to improve clarity and maintain consistency.
Suggested implementation:
```typescript
mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
mediaMessage.fileName ??= 'image.jpg';
mediaMessage.mimetype = 'image/jpeg';
} else {
mediaInput = isURL(mediaMessage.media)
? { url: mediaMessage.media }
: Buffer.from(mediaMessage.media, 'base64');
```
If there is another assignment to `mediaMessage.fileName` elsewhere in this function or code path, it should be removed to ensure the assignment is consolidated to this single location.
</issue_to_address>
Sorry, something went wrong.
| }; | ||
| } | ||
|
|
||
| const response = await axios.get(mediaMessage.media, config); |
There was a problem hiding this comment.
issue: Network errors from axios.get are not explicitly handled.
Catch errors from axios.get to prevent unhandled promise rejections when the image URL is unreachable or returns a non-200 status.
Sorry, something went wrong.
| } | ||
|
|
||
| mediaInput = await sharp(imageBuffer).jpeg().toBuffer(); | ||
| mediaMessage.fileName ??= 'image.jpg'; |
There was a problem hiding this comment.
suggestion: Redundant fileName assignment logic exists below.
Consolidate the fileName assignment to a single location to improve clarity and maintain consistency.
Suggested implementation:
mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
mediaMessage.fileName ??= 'image.jpg';
mediaMessage.mimetype = 'image/jpeg';
} else {
mediaInput = isURL(mediaMessage.media)
? { url: mediaMessage.media }
: Buffer.from(mediaMessage.media, 'base64');If there is another assignment to mediaMessage.fileName elsewhere in this function or code path, it should be removed to ensure the assignment is consolidated to this single location.
Sorry, something went wrong.
|
Aguardando o pessoal da evo aceita o pull pois a situação tá bem no envio de imagens. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
All images sent via the Baileys integration are now pre-processed and converted to JPEG format using the sharp library. This ensures better compatibility and prevents potential issues with unsupported formats.
Summary by Sourcery
Preprocess WhatsApp image attachments by fetching them via axios (respecting local proxy settings), converting buffers to JPEG using sharp, and updating file metadata to ensure compatibility.
New Features:
Enhancements: