修复可能导致收件失败问题回退优化自动刷新

This commit is contained in:
eoao
2026-01-28 22:13:23 +08:00
parent bfb896bae6
commit 5d2b49ff70
6 changed files with 52 additions and 59 deletions

View File

@@ -1,4 +0,0 @@
NODE_ENV = 'eo'
VITE_APP_TITLE = 'eo环境'
VITE_BASE_URL = ''
VITE_PWA_NAME = 'Cloud Mail'

View File

@@ -102,7 +102,6 @@ import {Icon} from "@iconify/vue";
import router from "@/router/index.js"; import router from "@/router/index.js";
import {useI18n} from 'vue-i18n'; import {useI18n} from 'vue-i18n';
import {toUtc} from "@/utils/day.js"; import {toUtc} from "@/utils/day.js";
import {AutoRefreshEnum} from "@/enums/setting-enum.js";
import {sleep} from "@/utils/time-utils.js"; import {sleep} from "@/utils/time-utils.js";
import {useSettingStore} from "@/store/setting.js"; import {useSettingStore} from "@/store/setting.js";
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
@@ -297,11 +296,13 @@ async function latest() {
while (true) { while (true) {
await sleep(1000) let autoRefresh = settingStore.settings.autoRefresh;
await sleep(autoRefresh > 1 ? autoRefresh * 1000 : 3000);
const latestId = sysEmailScroll.value.latestEmail?.emailId const latestId = sysEmailScroll.value.latestEmail?.emailId
if (settingStore.settings.autoRefresh === AutoRefreshEnum.DISABLED) { if (autoRefresh < 2) {
continue continue
} }
@@ -345,7 +346,7 @@ async function latest() {
} catch (e) { } catch (e) {
if (e.code === 401 || e.code === 403) { if (e.code === 401 || e.code === 403) {
settingStore.settings.autoRefresh = AutoRefreshEnum.DISABLED; settingStore.settings.autoRefresh = 0;
} }
console.error(e) console.error(e)
} }

View File

@@ -34,7 +34,6 @@ import {sleep} from "@/utils/time-utils.js";
import router from "@/router/index.js"; import router from "@/router/index.js";
import {Icon} from "@iconify/vue"; import {Icon} from "@iconify/vue";
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import {AutoRefreshEnum} from "@/enums/setting-enum.js";
defineOptions({ defineOptions({
name: 'email' name: 'email'
@@ -78,7 +77,8 @@ const existIds = new Set();
async function latest() { async function latest() {
while (true) { while (true) {
await sleep(1000) let autoRefresh = settingStore.settings.autoRefresh;
await sleep(autoRefresh > 1 ? autoRefresh * 1000 : 3000);
if (route.name !== 'email') { if (route.name !== 'email') {
continue; continue;
@@ -86,7 +86,7 @@ async function latest() {
const latestId = scroll.value.latestEmail?.emailId const latestId = scroll.value.latestEmail?.emailId
if (!scroll.value.firstLoad && settingStore.settings.autoRefresh === AutoRefreshEnum.ENABLED) { if (!scroll.value.firstLoad && autoRefresh > 1) {
try { try {
const accountId = accountStore.currentAccountId const accountId = accountStore.currentAccountId
const allReceive = scroll.value.latestEmail?.allReceive const allReceive = scroll.value.latestEmail?.allReceive
@@ -122,7 +122,7 @@ async function latest() {
} }
} catch (e) { } catch (e) {
if (e.code === 401 || e.code === 403) { if (e.code === 401 || e.code === 403) {
settingStore.settings.autoRefresh = AutoRefreshEnum.DISABLED; settingStore.settings.autoRefresh = 0;
} }
console.error(e) console.error(e)
} }

View File

@@ -829,7 +829,11 @@ const regKeyOptions = computed(() => [
const authRefreshOptions = computed(() => [ const authRefreshOptions = computed(() => [
{label: t('disable'), value: 0}, {label: t('disable'), value: 0},
{label: t('enable'), value: 1}, {label: '3s', value: 3},
{label: '5s', value: 5},
{label: '10s', value: 10},
{label: '15s', value: 15},
{label: '20s', value: 20},
]) ])
const tgChatId = ref([]) const tgChatId = ref([])

View File

@@ -27,10 +27,19 @@ const dbInit = {
await this.v2_6DB(c); await this.v2_6DB(c);
await this.v2_7DB(c); await this.v2_7DB(c);
await this.v2_8DB(c); await this.v2_8DB(c);
await this.v2_9DB(c);
await settingService.refresh(c); await settingService.refresh(c);
return c.text('success'); return c.text('success');
}, },
async v2_9DB(c) {
try {
await c.env.db.prepare(`UPDATE setting SET auto_refresh = 5 WHERE auto_refresh = 1;`).run();
} catch (e) {
console.warn(`跳过字段:${e.message}`);
}
},
async v2_8DB(c) { async v2_8DB(c) {
try { try {
await c.env.db.batch([ await c.env.db.batch([
@@ -44,8 +53,7 @@ const dbInit = {
async v2_7DB(c) { async v2_7DB(c) {
try { try {
await c.env.db.batch([ await c.env.db.batch([
c.env.db.prepare(`ALTER TABLE setting RENAME COLUMN auto_refresh_time TO auto_refresh;`), c.env.db.prepare(`ALTER TABLE setting RENAME COLUMN auto_refresh_time TO auto_refresh;`)
c.env.db.prepare(`UPDATE setting SET auto_refresh = 1 WHERE auto_refresh != 0;`)
]); ]);
} catch (e) { } catch (e) {
console.warn(`跳过字段:${e.message}`); console.warn(`跳过字段:${e.message}`);

View File

@@ -446,30 +446,22 @@ const emailService = {
allReceive = accountRow.allReceive; allReceive = accountRow.allReceive;
} }
let count = 0 let list = await orm(c).select({...email}).from(email)
let list = [] .leftJoin(
account,
while ((count < 6) && list.length === 0) { eq(account.accountId, email.accountId)
list = await orm(c).select({...email}).from(email) )
.leftJoin( .where(
account, and(
eq(account.accountId, email.accountId) gt(email.emailId, emailId),
) eq(email.userId, userId),
.where( eq(email.isDel, isDel.NORMAL),
and( eq(account.isDel, isDel.NORMAL),
gt(email.emailId, emailId), allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId), eq(email.type, emailConst.type.RECEIVE)
eq(email.isDel, isDel.NORMAL), ))
eq(account.isDel, isDel.NORMAL), .orderBy(desc(email.emailId))
allReceive ? eq(1,1) : eq(email.accountId, accountId), .limit(20);
eq(email.type, emailConst.type.RECEIVE)
))
.orderBy(desc(email.emailId))
.limit(20);
await sleep(5000);
count++
}
await this.emailAddAtt(c, list); await this.emailAddAtt(c, list);
@@ -630,24 +622,16 @@ const emailService = {
const { emailId } = params; const { emailId } = params;
let count = 0 let list = await orm(c).select({...email, userEmail: user.email}).from(email)
let list = [] .leftJoin(user, eq(email.userId, user.userId))
.where(
while ((count < 6) && list.length === 0) { and(
list = await orm(c).select({...email, userEmail: user.email}).from(email) gt(email.emailId, emailId),
.leftJoin(user, eq(email.userId, user.userId)) eq(email.type, emailConst.type.RECEIVE),
.where( ne(email.status, emailConst.status.SAVING)
and( ))
gt(email.emailId, emailId), .orderBy(desc(email.emailId))
eq(email.type, emailConst.type.RECEIVE), .limit(20);
ne(email.status, emailConst.status.SAVING)
))
.orderBy(desc(email.emailId))
.limit(20);
await sleep(5000);
count++
}
await this.emailAddAtt(c, list); await this.emailAddAtt(c, list);
@@ -660,10 +644,10 @@ const emailService = {
if (emailIds.length > 0) { if (emailIds.length > 0) {
const attsList = await attService.selectByEmailIds(c, emailIds); const attList = await attService.selectByEmailIds(c, emailIds);
list.forEach(emailRow => { list.forEach(emailRow => {
const atts = attsList.filter(attsRow => attsRow.emailId === emailRow.emailId); const atts = attList.filter(attRow => attRow.emailId === emailRow.emailId);
emailRow.attList = atts; emailRow.attList = atts;
}); });
} }