@c4t4/heyamigo 0.8.5 → 0.8.6

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,3 +1,4 @@
1
+ import { unlink } from 'fs/promises';
1
2
  import { getContentType, isJidGroup, jidDecode, jidNormalizedUser, } from 'baileys';
2
3
  import { getSession } from '../ai/sessions.js';
3
4
  import { config } from '../config.js';
@@ -77,15 +78,30 @@ async function processMessages(messages, sock, ownerJid, isHistorySync = false)
77
78
  const size = getMediaSize(msg);
78
79
  if (size !== null && size > limits.maxFileBytes) {
79
80
  await append(stored);
80
- const mb = (limits.maxFileBytes / (1024 * 1024)).toFixed(1);
81
81
  const quoted = isGroup && config.reply.quoteInGroups ? msg : undefined;
82
- await sendText(sock, stored.jid, `File too large (max ${mb} MB). I can't read this one try a smaller version.`, quoted).catch((err) => logger.error({ err, jid: stored.jid }, 'failed to send oversized-file notice'));
82
+ await sendText(sock, stored.jid, 'Could not process that, please try a smaller file.', quoted).catch((err) => logger.error({ err, jid: stored.jid }, 'failed to send oversized-file notice'));
83
83
  logger.info({ ...logCtx, size, cap: limits.maxFileBytes }, 'oversized media rejected');
84
84
  continue;
85
85
  }
86
86
  }
87
87
  // Download media if present (image, video, audio, document)
88
88
  const media = await downloadAndSave(msg, stored.jid);
89
+ // Post-download safety net: re-check against the real buffer size.
90
+ // Catches cases the pre-download gate missed — protobuf fileLength
91
+ // missing, nested in documentWithCaptionMessage, stickers, etc.
92
+ // Only enforced when we'd otherwise respond; silent groups keep the
93
+ // archive intact regardless of size.
94
+ if (media &&
95
+ limits.maxFileBytes !== null &&
96
+ decision.respond &&
97
+ media.bytes > limits.maxFileBytes) {
98
+ await unlink(media.mediaPath).catch(() => undefined);
99
+ await append(stored);
100
+ const quoted = isGroup && config.reply.quoteInGroups ? msg : undefined;
101
+ await sendText(sock, stored.jid, 'Could not process that, please try a smaller file.', quoted).catch((err) => logger.error({ err, jid: stored.jid }, 'failed to send oversized-file notice'));
102
+ logger.info({ ...logCtx, bytes: media.bytes, cap: limits.maxFileBytes }, 'oversized media rejected (post-download)');
103
+ continue;
104
+ }
89
105
  if (media) {
90
106
  stored.mediaType = media.mediaType;
91
107
  stored.mediaPath = media.mediaPath;
@@ -98,6 +98,7 @@ export async function downloadAndSave(msg, jid) {
98
98
  mediaType,
99
99
  mediaPath: filePath,
100
100
  mediaMime: mimetype,
101
+ bytes: buffer.length,
101
102
  };
102
103
  }
103
104
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4t4/heyamigo",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "WhatsApp AI bot powered by Claude with long-term memory, browser control, and role-based access",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",