Skip to content

Commit cb34414

Browse files
committed
image upload: code review
1 parent 64b2f9d commit cb34414

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

lib/notify.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,36 +148,38 @@ async function withTelegram(note, messageSettings, login = false) {
148148

149149
return new Promise(async(resolve, reject) => {
150150
try {
151-
// Check for image in note content
152-
const noteContent = await getNoteContents(note.url)
153-
const imageInfo = extractFirstImage(noteContent.content)
151+
// Handle image processing independently
152+
let hasImage = false
153+
try {
154+
const noteContent = await getNoteContents(note.url)
155+
const imageInfo = extractFirstImage(noteContent.content)
154156

155-
if (imageInfo?.imageUrl) {
156-
console.log('Found image in note, sending photo first')
157+
if (imageInfo?.imageUrl) {
158+
console.log('Found image in note, sending photo first')
157159

158-
// Create caption with subject and alt text
159-
let caption = markdownv2.bold(markdownv2.escape(msg.prefix))
160-
caption += markdownv2.escape(`\n\n`)
161-
caption += markdownv2.underline(markdownv2.escape(msg.title))
162-
caption += markdownv2.escape(`\n\n`)
160+
// Create caption with subject and alt text
161+
let caption = markdownv2.bold(markdownv2.escape(msg.prefix))
162+
caption += markdownv2.escape(`\n\n`)
163+
caption += markdownv2.underline(markdownv2.escape(msg.title))
164+
caption += markdownv2.escape(`\n\n`)
163165

164-
// Use alt text if available, otherwise use preview text
165-
const captionText = imageInfo.altText || msg.previewText
166-
caption += markdownv2.escape(captionText)
166+
// Use alt text if available, otherwise use preview text
167+
const captionText = imageInfo.altText || msg.previewText
168+
caption += markdownv2.escape(captionText)
167169

168-
if(showEditLink) {
169-
caption += markdownv2.escape(`\n\n`)
170-
caption += markdownv2.url("Edit note", msg.webUrl)
171-
}
170+
if(showEditLink) {
171+
caption += markdownv2.escape(`\n\n`)
172+
caption += markdownv2.url("Edit note", msg.webUrl)
173+
}
172174

173-
// Download and send image with size limits
174-
try {
175+
// Download and send image with size limits
175176
const imageBuffer = await downloadImage(imageInfo.dataFullresSrc || imageInfo.imageUrl)
176177
await sendPhotoToTelegram(imageBuffer, caption, channelHandle)
177-
} catch (imageErr) {
178-
console.warn('Failed to process image:', imageErr.message)
179-
// Continue without image - note text will still be sent
178+
hasImage = true
180179
}
180+
} catch (imageErr) {
181+
console.warn('Image processing failed, continuing with text message:', imageErr.message)
182+
// Image processing failure doesn't affect text message flow
181183
}
182184

183185
// Send note body text
@@ -198,7 +200,7 @@ async function withTelegram(note, messageSettings, login = false) {
198200
status: 200,
199201
title: msg.title,
200202
body: msg.previewText,
201-
hasImage: !!imageInfo
203+
hasImage
202204
})
203205
} catch (err) {
204206
console.error('Title: ', msg.title)

lib/onenote.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function getRandomNote(notes, sectionHandle) {
313313
localStorage.getItem(`recent_${sectionHandle}`, true) || []
314314

315315
if (recentNotes.includes(note.id)) {
316-
getRandomNote(notes)
316+
return getRandomNote(notes, sectionHandle)
317317
}
318318

319319
return note
@@ -365,7 +365,7 @@ async function getImageSize(imageUrl) {
365365
})
366366
.catch(err => {
367367
console.error('getImageSize', err)
368-
reject(new Error(err))
368+
reject(err)
369369
})
370370
})
371371
}

0 commit comments

Comments
 (0)