新增邮件发送和管理员功能

This commit is contained in:
eoao
2025-05-29 17:38:50 +08:00
parent de742d31e7
commit 2341d14b2d
364 changed files with 24202 additions and 1079 deletions

View File

@@ -3,9 +3,7 @@ import emailService from '../service/email-service';
import accountService from '../service/account-service';
import settingService from '../service/setting-service';
import attService from '../service/att-service';
import r2Service from '../service/r2-service';
import constant from '../const/constant';
import { v4 as uuidv4 } from 'uuid';
import fileUtils from '../utils/file-utils';
export async function email(message, env, ctx) {
@@ -40,35 +38,29 @@ export async function email(message, env, ctx) {
accountId: account.accountId
};
const emailRow = await emailService.receive({ env }, params);
const attachments = [];
const cidAttachments = [];
if (!env.r2) {
console.warn('r2对象存储未配置, 附件取消保存');
return;
}
if (email.attachments.length > 0) {
let attachments = email.attachments.map(item => {
let attachment = { ...item };
attachment.emailId = emailRow.emailId;
attachment.userId = emailRow.userId;
attachment.accountId = emailRow.accountId;
attachment.key = constant.ATTACHMENT_PREFIX + uuidv4() + fileUtils.getExtFileName(item.filename);
attachment.size = item.content.length ?? item.content.byteLength;
return attachment;
});
await attService.addAtt({ env }, attachments);
for (let attachment of attachments) {
await r2Service.putObj({ env }, attachment.key, attachment.content, {
contentType: attachment.mimeType,
contentDisposition: `attachment; filename="${attachment.filename}"`
});
for(let item of email.attachments) {
let attachment = { ...item };
attachment.key = constant.ATTACHMENT_PREFIX + await fileUtils.getBuffHash(attachment.content) + fileUtils.getExtFileName(item.filename);
attachment.size = item.content.length ?? item.content.byteLength;
attachments.push(attachment);
if (attachment.contentId) {
cidAttachments.push(attachment)
}
}
const emailRow = await emailService.receive({ env }, params, cidAttachments);
attachments.forEach(attachment => {
attachment.emailId = emailRow.emailId;
attachment.userId = emailRow.userId;
attachment.accountId = emailRow.accountId;
})
await attService.addAtt({ env }, attachments);
} catch (e) {
console.error('邮件接收异常: ', e);
}