feat: AI verification code recognition settings
This commit is contained in:
@@ -128,6 +128,10 @@ export const settingConst = {
|
||||
OPEN: 0,
|
||||
CLOSE: 1
|
||||
},
|
||||
aiCode: {
|
||||
OPEN: 0,
|
||||
CLOSE: 1
|
||||
},
|
||||
authRefresh: {
|
||||
OPEN: 1,
|
||||
CLOSE: 0
|
||||
|
||||
@@ -28,7 +28,9 @@ export async function email(message, env, ctx) {
|
||||
noRecipient,
|
||||
blackSubject,
|
||||
blackContent,
|
||||
blackFrom
|
||||
blackFrom,
|
||||
aiCode,
|
||||
aiCodeFilter
|
||||
} = await settingService.query({ env });
|
||||
|
||||
if (receive === settingConst.receive.CLOSE) {
|
||||
@@ -90,7 +92,7 @@ export async function email(message, env, ctx) {
|
||||
}
|
||||
|
||||
const toName = email.to.find(item => item.address === message.to)?.name || '';
|
||||
const code = await aiService.extractCode({ env }, email);
|
||||
const code = aiCode === settingConst.aiCode.OPEN && checkAiCodeFilter(aiCodeFilter, email) ? await aiService.extractCode({ env }, email) : '';
|
||||
|
||||
const params = {
|
||||
toEmail: message.to,
|
||||
@@ -183,6 +185,19 @@ export async function email(message, env, ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkAiCodeFilter(aiCodeFilterStr, email) {
|
||||
const filterList = aiCodeFilterStr ? aiCodeFilterStr.split(',').map(item => item.trim().toLowerCase()).filter(Boolean) : [];
|
||||
|
||||
if (filterList.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const fromEmail = (email.from?.address || '').trim().toLowerCase();
|
||||
const fromDomain = emailUtils.getDomain(fromEmail).toLowerCase();
|
||||
|
||||
return filterList.some(item => item === fromEmail || item === fromDomain);
|
||||
}
|
||||
|
||||
function checkBlock(blackSubjectStr, blackContentStr, blackFromStr, email) {
|
||||
|
||||
const blackFromList = blackFromStr ? blackFromStr.split(',') : []
|
||||
|
||||
@@ -49,6 +49,8 @@ export const setting = sqliteTable('setting', {
|
||||
emailPrefixFilter: text('email_prefix_filter').default('').notNull(),
|
||||
blackSubject: text('black_subject').default('').notNull(),
|
||||
blackContent: text('black_content').default('').notNull(),
|
||||
blackFrom: text('black_from').default('').notNull()
|
||||
blackFrom: text('black_from').default('').notNull(),
|
||||
aiCode: integer('ai_code').default(1).notNull(),
|
||||
aiCodeFilter: text('ai_code_filter').default('').notNull()
|
||||
});
|
||||
export default setting
|
||||
|
||||
@@ -49,6 +49,18 @@ const dbInit = {
|
||||
} catch (e) {
|
||||
console.warn(`跳过字段:${e.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code INTEGER NOT NULL DEFAULT 1;`).run();
|
||||
} catch (e) {
|
||||
console.warn(`跳过字段:${e.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code_filter TEXT NOT NULL DEFAULT '';`).run();
|
||||
} catch (e) {
|
||||
console.warn(`跳过字段:${e.message}`);
|
||||
}
|
||||
},
|
||||
|
||||
async v2_9DB(c) {
|
||||
@@ -592,7 +604,9 @@ const dbInit = {
|
||||
title TEXT NOT NULL,
|
||||
auto_refresh INTEGER NOT NULL,
|
||||
register_verify INTEGER NOT NULL,
|
||||
add_email_verify INTEGER NOT NULL
|
||||
add_email_verify INTEGER NOT NULL,
|
||||
ai_code INTEGER NOT NULL DEFAULT 1,
|
||||
ai_code_filter TEXT NOT NULL DEFAULT ''
|
||||
)
|
||||
`).run();
|
||||
|
||||
|
||||
@@ -133,6 +133,10 @@ const settingService = {
|
||||
params.emailPrefixFilter = params.emailPrefixFilter + '';
|
||||
}
|
||||
|
||||
if (Array.isArray(params.aiCodeFilter)) {
|
||||
params.aiCodeFilter = params.aiCodeFilter + '';
|
||||
}
|
||||
|
||||
params.resendTokens = JSON.stringify(resendTokens);
|
||||
await orm(c).update(setting).set({ ...params }).returning().get();
|
||||
await this.refresh(c);
|
||||
|
||||
Reference in New Issue
Block a user