feat: display verification code in frontend email list
This commit is contained in:
@@ -35,7 +35,11 @@ const dbInit = {
|
||||
|
||||
async v3_0DB(c) {
|
||||
try {
|
||||
await c.env.db.prepare(`ALTER TABLE email ADD COLUMN code TEXT NOT NULL DEFAULT '';`).run();
|
||||
await c.env.db.batch([
|
||||
await c.env.db.prepare(`ALTER TABLE email ADD COLUMN code TEXT NOT NULL DEFAULT '';`).run(),
|
||||
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code INTEGER NOT NULL DEFAULT 1;`).run(),
|
||||
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code_filter TEXT NOT NULL DEFAULT '';`).run()
|
||||
]);
|
||||
} catch (e) {
|
||||
console.warn(`跳过字段:${e.message}`);
|
||||
}
|
||||
@@ -50,17 +54,6 @@ const dbInit = {
|
||||
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) {
|
||||
|
||||
@@ -22,7 +22,7 @@ const aiService = {
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
content: 'You extract verification codes from emails. Return only JSON like {"code":"123456"} or {"code":""}. Do not explain.'
|
||||
content: 'You extract verification codes from emails. Return only JSON like {"code":"123456"} or {"code":""}. The code must be 6 characters or fewer and must not contain spaces. If the code is longer than 6 characters or contains spaces, return {"code":""}. Do not explain.'
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
@@ -35,7 +35,15 @@ const aiService = {
|
||||
|
||||
const content = typeof result === 'string' ? result : result?.response || '';
|
||||
const json = JSON.parse(content);
|
||||
return typeof json.code === 'string' ? json.code.trim().slice(0, 64) : '';
|
||||
if (typeof json.code !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (json.code.length > 6 || /\s/.test(json.code)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return json.code;
|
||||
} catch (e) {
|
||||
console.error('验证码提取失败: ', e);
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user