fix: update address timestamp on send mail and refactor TG attachment guard (#896)

fix: update address timestamp on send mail, refactor TG attachment guard

- Call updateAddressUpdatedAt after successful send mail to keep
  address activity timestamp up to date
- Refactor Telegram attachment push: replace early return with if block
  to prevent skipping future logic after attachment section

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dream Hunter
2026-03-14 02:39:18 +08:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 9ee21da8a9
commit e7df77cac0
2 changed files with 26 additions and 23 deletions
+3 -1
View File
@@ -8,7 +8,7 @@ import i18n from '../i18n';
import { CONSTANTS } from '../constants' import { CONSTANTS } from '../constants'
import { getJsonSetting, getDomains, getIntValue, getBooleanValue, getStringValue, getJsonObjectValue, getSplitStringListValue } from '../utils'; import { getJsonSetting, getDomains, getIntValue, getBooleanValue, getStringValue, getJsonObjectValue, getSplitStringListValue } from '../utils';
import { GeoData } from '../models' import { GeoData } from '../models'
import { handleListQuery } from '../common' import { handleListQuery, updateAddressUpdatedAt } from '../common'
export const api = new Hono<HonoCustomType>() export const api = new Hono<HonoCustomType>()
@@ -222,6 +222,8 @@ export const sendMail = async (
console.warn(`Failed to update balance for ${address}`); console.warn(`Failed to update balance for ${address}`);
} }
} }
// update address updated_at
updateAddressUpdatedAt(c, address);
// save to sendbox // save to sendbox
try { try {
const reqIp = c.req.raw.headers.get("cf-connecting-ip") const reqIp = c.req.raw.headers.get("cf-connecting-ip")
+23 -22
View File
@@ -439,28 +439,29 @@ export async function sendMailToTelegram(
...Markup.inlineKeyboard([...buttons]) ...Markup.inlineKeyboard([...buttons])
}); });
// send attachments // send attachments
if (!getBooleanValue(c.env.ENABLE_TG_PUSH_ATTACHMENT)) return; if (getBooleanValue(c.env.ENABLE_TG_PUSH_ATTACHMENT)) {
const validAttachments = attachments.filter(att => { const validAttachments = attachments.filter(att => {
if (att.content.byteLength > TG_MAX_FILE_SIZE) { if (att.content.byteLength > TG_MAX_FILE_SIZE) {
console.log(`Skipping attachment ${att.filename}: ${(att.content.byteLength / 1024 / 1024).toFixed(1)}MB exceeds 50MB limit`); console.log(`Skipping attachment ${att.filename}: ${(att.content.byteLength / 1024 / 1024).toFixed(1)}MB exceeds 50MB limit`);
return false; return false;
} }
return true; return true;
}); });
if (validAttachments.length > 0) { if (validAttachments.length > 0) {
const caption = `From: ${parsedEmailContext.parsedEmail?.sender || ""}\nSubject: ${parsedEmailContext.parsedEmail?.subject || ""}`; const caption = `From: ${parsedEmailContext.parsedEmail?.sender || ""}\nSubject: ${parsedEmailContext.parsedEmail?.subject || ""}`;
const batchSize = 6; const batchSize = 6;
for (let i = 0; i < validAttachments.length; i += batchSize) { for (let i = 0; i < validAttachments.length; i += batchSize) {
const batch = validAttachments.slice(i, i + batchSize); const batch = validAttachments.slice(i, i + batchSize);
try { try {
const mediaGroup: InputMediaDocument[] = batch.map((att, idx) => ({ const mediaGroup: InputMediaDocument[] = batch.map((att, idx) => ({
type: 'document', type: 'document',
media: { source: Buffer.from(att.content), filename: att.filename }, media: { source: Buffer.from(att.content), filename: att.filename },
...(i === 0 && idx === 0 ? { caption } : {}), ...(i === 0 && idx === 0 ? { caption } : {}),
})); }));
await bot.telegram.sendMediaGroup(targetUserId, mediaGroup); await bot.telegram.sendMediaGroup(targetUserId, mediaGroup);
} catch (e) { } catch (e) {
console.error(`Failed to send attachment batch ${i / batchSize + 1}:`, e); console.error(`Failed to send attachment batch ${i / batchSize + 1}:`, e);
}
} }
} }
} }