@peopl-health/nexus 3.13.10 → 3.13.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
|
+
const sharp = require('sharp');
|
|
2
3
|
const { v4: uuidv4 } = require('uuid');
|
|
3
4
|
const twilio = require('twilio');
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ const runtimeConfig = require('../config/runtimeConfig');
|
|
|
6
7
|
const { generatePresignedUrl } = require('../config/awsConfig');
|
|
7
8
|
|
|
8
9
|
const { sanitizeMediaFilename } = require('../utils/sanitizerUtils');
|
|
9
|
-
const { validateMedia, getMediaType } = require('../utils/mediaValidator');
|
|
10
|
+
const { validateMedia, getMediaType, MEDIA_LIMITS, STICKER_DIMENSIONS } = require('../utils/mediaValidator');
|
|
10
11
|
const { logger } = require('../utils/logger');
|
|
11
12
|
const { calculateDelay } = require('../utils/scheduleUtils');
|
|
12
13
|
|
|
@@ -292,7 +293,7 @@ class TwilioProvider extends MessageProvider {
|
|
|
292
293
|
|
|
293
294
|
try {
|
|
294
295
|
const response = await axios.get(fileUrl, { responseType: 'arraybuffer' });
|
|
295
|
-
|
|
296
|
+
let buffer = Buffer.from(response.data);
|
|
296
297
|
let contentType = messageData.contentType || response.headers['content-type'];
|
|
297
298
|
const declaredType = messageData.fileType || null;
|
|
298
299
|
|
|
@@ -306,6 +307,23 @@ class TwilioProvider extends MessageProvider {
|
|
|
306
307
|
contentType = fallbackType || 'application/octet-stream';
|
|
307
308
|
}
|
|
308
309
|
|
|
310
|
+
if (contentType === 'image/webp') {
|
|
311
|
+
const { width, height } = await sharp(buffer).metadata();
|
|
312
|
+
const isSticker = buffer.length < MEDIA_LIMITS.sticker
|
|
313
|
+
&& width === STICKER_DIMENSIONS.width
|
|
314
|
+
&& height === STICKER_DIMENSIONS.height;
|
|
315
|
+
if (!isSticker) {
|
|
316
|
+
buffer = await sharp(buffer)
|
|
317
|
+
.flatten({ background: '#ffffff' })
|
|
318
|
+
.jpeg({ quality: 85 })
|
|
319
|
+
.toBuffer();
|
|
320
|
+
contentType = 'image/jpeg';
|
|
321
|
+
if (messageData.fileName) {
|
|
322
|
+
messageData.fileName = messageData.fileName.replace(/\.[^.]+$/, '.jpg');
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
309
327
|
const validation = validateMedia(buffer, contentType);
|
|
310
328
|
const mediaType = validation.valid ? validation.mediaType : (declaredType || getMediaType(contentType));
|
|
311
329
|
|
|
@@ -3,9 +3,11 @@ const MEDIA_LIMITS = {
|
|
|
3
3
|
video: 16 * 1024 * 1024, // 16MB
|
|
4
4
|
audio: 16 * 1024 * 1024, // 16MB
|
|
5
5
|
document: 100 * 1024 * 1024, // 100MB (PDFs, etc.)
|
|
6
|
-
sticker:
|
|
6
|
+
sticker: 100 * 1024 // 100KB
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
const STICKER_DIMENSIONS = { width: 512, height: 512 };
|
|
10
|
+
|
|
9
11
|
const ALLOWED_FORMATS = {
|
|
10
12
|
image: ['image/jpeg', 'image/png', 'image/webp'],
|
|
11
13
|
video: ['video/mp4', 'video/3gpp'],
|
|
@@ -94,5 +96,6 @@ module.exports = {
|
|
|
94
96
|
validateMediaFormat,
|
|
95
97
|
getMediaType,
|
|
96
98
|
MEDIA_LIMITS,
|
|
97
|
-
ALLOWED_FORMATS
|
|
99
|
+
ALLOWED_FORMATS,
|
|
100
|
+
STICKER_DIMENSIONS
|
|
98
101
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peopl-health/nexus",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.11",
|
|
4
4
|
"description": "Core messaging and assistant library for WhatsApp communication platforms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"pdf-lib": "1.17.1",
|
|
79
79
|
"pino": "10.0.0",
|
|
80
80
|
"pino-pretty": "^10.2.0",
|
|
81
|
+
"sharp": "0.32.6",
|
|
81
82
|
"uuid": "^9.0.0"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
@@ -85,7 +86,6 @@
|
|
|
85
86
|
"eslint": "^8.47.0",
|
|
86
87
|
"eslint-plugin-import": "^2.32.0",
|
|
87
88
|
"jest": "^29.6.2",
|
|
88
|
-
"sharp": "0.32.6",
|
|
89
89
|
"typescript": "^5.1.6"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|