-
Notifications
You must be signed in to change notification settings - Fork 0
Description
⚠️ Issues & Concerns
Security & Best Practices:
-
Potential memory exhaustion (
onenote.js:403-409):res.on('data', chunk => { downloadedBytes += chunk.length if (downloadedBytes > maxSizeBytes) { return callback(new Error(`Image download exceeded size limit: ${downloadedBytes} bytes`)) } chunks.push(chunk) })
The chunks array continues to grow even after size limit is exceeded. Should abort the request immediately.
-
Inconsistent timeout handling (
onenote.js:356,notify.js:269):getImageSize(): 10s response, 15s deadlinedownloadImage(): 30s response, 45s deadlinesendPhotoToTelegram(): 30s response, 45s deadline
Consider standardizing timeout values or making them configurable.
-
Missing input validation (
onenote.js:327-343):
extractFirstImage()doesn't validate thathtmlContentis a string or handle null/undefined inputs.
Code Quality:
-
Recursive call potential (
onenote.js:316):if (recentNotes.includes(note.id)) { return getRandomNote(notes, sectionHandle) }
Could cause stack overflow if all notes are recent. Consider iterative approach or max retry limit.
-
Hardcoded filename (
notify.js:268):.attach('photo', imageBuffer, 'image.jpg')
Should derive filename from image URL or content-type header.
-
Unclear error propagation (
notify.js:180-183):
Image errors are logged as warnings but might mask important issues. Consider differentiating between expected vs unexpected errors.
🔧 Recommendations
-
Fix memory leak in downloadImage():
res.on('data', chunk => { downloadedBytes += chunk.length if (downloadedBytes > maxSizeBytes) { res.destroy() // Abort the request return callback(new Error(`Image download exceeded size limit`)) } chunks.push(chunk) })
-
Add input validation:
function extractFirstImage(htmlContent) { if (!htmlContent || typeof htmlContent !== 'string') { return null } // ... rest of function }