feat: fix backend sql error;fix frontend i18n display error

This commit is contained in:
2025-07-29 15:35:34 +08:00
parent 32320e1cb0
commit 7ee074249f
4 changed files with 43 additions and 48 deletions

View File

@@ -100,7 +100,7 @@ app.delete('/api/messages', async (req, res) => {
return res.status(400).send('Recipient is required');
}
try {
await db.execute('DELETE FROM emails WHERE recipient = ?', [recipient]);
await db.execute('DELETE FROM emails WHERE recipient LIKE ?', [`%${recipient}%`]);
logger.info('All messages for recipient deleted successfully', { recipient });
res.status(204).send(); // No Content
} catch (error) {
@@ -142,14 +142,19 @@ wss.on('connection', (ws, req) => {
});
emitter.on('newEmail', (email) => {
const recipient = email.recipient;
if (clients.has(recipient)) {
const ws = clients.get(recipient);
logger.info(`Sending new email notification to`, { recipient });
ws.send(JSON.stringify(email));
const dbRecipient = email.recipient; // 比如 "6471" <6471@shenjianl.cn>
// 遍历所有 clients用 includes 判断
for (const [clientRecipient, ws] of clients.entries()) {
if (dbRecipient.includes(clientRecipient)) {
logger.info(`Sending new email notification to`, { recipient: clientRecipient });
ws.send(JSON.stringify(email));
break; // 如果只想发给第一个匹配的就 break
}
}
});
// Start API server
server.listen(apiPort, () => {
logger.info(`Backend API and WebSocket server listening at http://localhost:${apiPort}`);

View File

@@ -23,7 +23,7 @@ async function saveEmail(stream) {
const recipient = parsed.to ? parsed.to.text : 'undisclosed-recipients';
const sender = parsed.from ? parsed.from.text : 'unknown-sender';
const subject = parsed.subject;
const subject = parsed.subject || 'No Subject';
const body = parsed.text || (parsed.html || '');
const [result] = await db.execute(