mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-15 12:29:07 +08:00
* feat: add i18n support for backend API and Telegram bot - Add comprehensive i18n support for all backend API error messages (zh/en) - Add /lang command for Telegram bot to set language preference - Add bilingual command descriptions for Telegram bot - Support per-user language preference stored in KV - Global push uses DEFAULT_LANG, user push uses saved preference 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: improve Telegram bot language preference feature - Add internationalized message for disabled language feature - Fix hardcoded English message in /lang command - Optimize getTgMessages calls (reduce from 3 to 1 call) - Remove verbose comments for better code clarity - Add TgLangFeatureDisabledMsg to i18n (zh/en) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { Context } from "hono";
|
|
import { getBooleanValue } from "../utils";
|
|
import i18n from "../i18n";
|
|
|
|
|
|
export default {
|
|
getAutoReply: async (c: Context<HonoCustomType>) => {
|
|
const msgs = i18n.getMessagesbyContext(c);
|
|
if (!getBooleanValue(c.env.ENABLE_AUTO_REPLY)) {
|
|
return c.text(msgs.AutoReplyDisabledMsg, 403)
|
|
}
|
|
const { address } = c.get("jwtPayload")
|
|
const results = await c.env.DB.prepare(
|
|
`SELECT * FROM auto_reply_mails where address = ? `
|
|
).bind(address).first();
|
|
if (!results) {
|
|
return c.json({});
|
|
}
|
|
return c.json({
|
|
subject: results.subject,
|
|
message: results.message,
|
|
enabled: results.enabled == 1,
|
|
source_prefix: results.source_prefix,
|
|
name: results.name,
|
|
})
|
|
},
|
|
saveAutoReply: async (c: Context<HonoCustomType>) => {
|
|
const msgs = i18n.getMessagesbyContext(c);
|
|
if (!getBooleanValue(c.env.ENABLE_AUTO_REPLY)) {
|
|
return c.text(msgs.AutoReplyDisabledMsg, 403)
|
|
}
|
|
const { address } = c.get("jwtPayload");
|
|
const { auto_reply } = await c.req.json();
|
|
const { name, subject, source_prefix, message, enabled } = auto_reply;
|
|
if ((!subject || !message) && enabled) {
|
|
return c.text(msgs.InvalidAutoReplyMsg, 400)
|
|
}
|
|
else if (subject.length > 255 || message.length > 255) {
|
|
return c.text(msgs.SubjectOrMessageTooLongMsg, 400)
|
|
}
|
|
const { success } = await c.env.DB.prepare(
|
|
`INSERT OR REPLACE INTO auto_reply_mails`
|
|
+ ` (name, address, source_prefix, subject, message, enabled)`
|
|
+ ` VALUES (?, ?, ?, ?, ?, ?)`
|
|
).bind(
|
|
name || '', address, source_prefix || '',
|
|
subject || '', message || '', enabled ? 1 : 0
|
|
).run();
|
|
if (!success) {
|
|
return c.text(msgs.OperationFailedMsg, 500)
|
|
}
|
|
return c.json({
|
|
success: success
|
|
})
|
|
}
|
|
}
|