feat: add restricted stability test mode

This commit is contained in:
abaishu0730 committed 2026-10-22 10:23:04 +08:00
1 parent 0f1631b35a
commit 0890b01d77
19 files changed
+383 -25

No files matched your search

+3
View File
@@ -69,6 +69,7 @@ class OrderRuleDispatcher{
async dispatch(batch,config,{manual=false}={}){
let transport,sending=false;
try{
require('./restricted-test.cjs').assertBatch(this.store,batch,config);
if(batch.channelId&&batch.channelId!==config.channelId){
this.store.finishSending(batch.id,'failed','批次固定的发件邮箱与当前渠道不同,请核实邮箱设置后生成新批次。');return;
}
@@ -85,6 +86,7 @@ class OrderRuleDispatcher{
if(manual?this.stopped||!this.providersReady()||!this.store.providersReady():!this.ready()||this.store.settings().channelId!==config.channelId)throw Error('发送已暂停或配置已变更。');
if(!manual&&this.clock().getTime()-Date.parse(batch.cutoff)>1800000)throw Error('冻结发送队列超过30分钟。');
this.mail.store.guard(channel.id,channel.version);
require('./restricted-test.cjs').assertBatch(this.store,batch,config);
this.store.beginSending(batch.id,{manual});sending=true;
const result=await transport.sendMail({from:{address:channel.email,name:channel.name},to:[...batch.to],cc:[...batch.cc],subject:batch.subject,text:batch.text,html:batch.html,attachments,messageId:`<${batch.id}@${channel.email.split('@')[1]}>`,disableFileAccess:true,disableUrlAccess:true});
const accepted=new Set((result?.accepted||[]).map(address=>String(address.address||address).toLowerCase()));
@@ -107,6 +109,7 @@ class OrderRuleDispatcher{
const replay=record=>{if(record.inputHash!==inputHash)fail('此幂等标识已用于不同的补发请求。',409);return this.store.get('batches',record.batchId);};
const prior=this.store.get('resend-requests',requestId);if(prior)return replay(prior);
const original=this.store.get('batches',id);if(!original)fail('批次不存在。',404);
require('./restricted-test.cjs').assertBatch(this.store,original,{...this.store.settings(),channelId:original.channelId});
if(!original.channelId)fail('原批次未冻结发件邮箱,不能补发。',409);
const operation=this.mail.exclusive(original.channelId,async()=>{
const previous=this.store.get('resend-requests',requestId);if(previous)return replay(previous);