(imageBuffer: Buffer)
| 230 | |
| 231 | // Add image to buffer and return placeholder |
| 232 | addImage(imageBuffer: Buffer): string { |
| 233 | // Validate image size |
| 234 | if (imageBuffer.length > MAX_IMAGE_SIZE) { |
| 235 | throw new Error( |
| 236 | `Image size ${(imageBuffer.length / 1024 / 1024).toFixed(1)}MB exceeds maximum allowed size of ${MAX_IMAGE_SIZE / 1024 / 1024}MB`, |
| 237 | ); |
| 238 | } |
| 239 | |
| 240 | // Check image count limit |
| 241 | if (this._imageMap.size >= MAX_IMAGE_COUNT) { |
| 242 | throw new Error(`Cannot add more than ${MAX_IMAGE_COUNT} images`); |
| 243 | } |
| 244 | |
| 245 | // Check total memory usage |
| 246 | const currentMemoryUsage = Array.from(this._imageMap.values()).reduce( |
| 247 | (total, buffer) => total + buffer.length, |
| 248 | 0, |
| 249 | ); |
| 250 | |
| 251 | if (currentMemoryUsage + imageBuffer.length > MAX_TOTAL_IMAGE_MEMORY) { |
| 252 | const currentUsageMB = (currentMemoryUsage / 1024 / 1024).toFixed(1); |
| 253 | const maxUsageMB = MAX_TOTAL_IMAGE_MEMORY / 1024 / 1024; |
| 254 | throw new Error( |
| 255 | `Adding image would exceed total memory limit. Current usage: ${currentUsageMB}MB, Maximum: ${maxUsageMB}MB`, |
| 256 | ); |
| 257 | } |
| 258 | |
| 259 | this._imageCounter++; |
| 260 | const placeholder = `[Image #${this._imageCounter}]`; |
| 261 | this._imageMap.set(placeholder, imageBuffer); |
| 262 | this.insertText(placeholder); |
| 263 | return placeholder; |
| 264 | } |
| 265 | |
| 266 | // Get all images for message formatting |
| 267 | getAllImages(): Map<string, Buffer> { |
no test coverage detected