新增全部邮件自动刷新
This commit is contained in:
@@ -2,17 +2,22 @@ import app from '../hono/hono';
|
||||
import emailService from '../service/email-service';
|
||||
import result from '../model/result';
|
||||
|
||||
app.get('/allEmail/list',async (c) => {
|
||||
app.get('/allEmail/list', async (c) => {
|
||||
const data = await emailService.allList(c, c.req.query());
|
||||
return c.json(result.ok(data));
|
||||
})
|
||||
|
||||
app.delete('/allEmail/delete',async (c) => {
|
||||
app.delete('/allEmail/delete', async (c) => {
|
||||
const list = await emailService.physicsDelete(c, c.req.query());
|
||||
return c.json(result.ok(list));
|
||||
})
|
||||
|
||||
app.delete('/allEmail/batchDelete',async (c) => {
|
||||
app.delete('/allEmail/batchDelete', async (c) => {
|
||||
await emailService.batchDelete(c, c.req.query());
|
||||
return c.json(result.ok());
|
||||
})
|
||||
|
||||
app.get('/allEmail/latest', async (c) => {
|
||||
const list = await emailService.allEmailLatest(c, c.req.query());
|
||||
return c.json(result.ok(list));
|
||||
})
|
||||
|
||||
@@ -74,7 +74,7 @@ const premKey = {
|
||||
'user:set-status': ['/user/setStatus'],
|
||||
'user:set-type': ['/user/setType'],
|
||||
'user:delete': ['/user/delete','/user/deleteAccount'],
|
||||
'all-email:query': ['/allEmail/list'],
|
||||
'all-email:query': ['/allEmail/list','/allEmail/latest'],
|
||||
'all-email:delete': ['/allEmail/delete','/allEmail/batchDelete'],
|
||||
'setting:query': ['/setting/query'],
|
||||
'setting:set': ['/setting/set', '/setting/setBackground','/setting/deleteBackground'],
|
||||
|
||||
@@ -33,8 +33,8 @@ const emailService = {
|
||||
accountId = Number(accountId);
|
||||
allReceive = Number(allReceive);
|
||||
|
||||
if (size > 30) {
|
||||
size = 30;
|
||||
if (size > 50) {
|
||||
size = 50;
|
||||
}
|
||||
|
||||
if (!emailId) {
|
||||
@@ -109,7 +109,7 @@ const emailService = {
|
||||
eq(email.type, type),
|
||||
eq(email.isDel, isDel.NORMAL)
|
||||
))
|
||||
.orderBy(desc(email.emailId)).limit(size).get();
|
||||
.orderBy(desc(email.emailId)).limit(1).get();
|
||||
|
||||
let [list, totalRow, latestEmail] = await Promise.all([listQuery, totalQuery, latestEmailQuery]);
|
||||
|
||||
@@ -118,14 +118,8 @@ const emailService = {
|
||||
isStar: item.starId != null ? 1 : 0
|
||||
}));
|
||||
|
||||
const emailIds = list.map(item => item.emailId);
|
||||
|
||||
const attsList = await attService.selectByEmailIds(c, emailIds);
|
||||
|
||||
list.forEach(emailRow => {
|
||||
const atts = attsList.filter(attsRow => attsRow.emailId === emailRow.emailId);
|
||||
emailRow.attList = atts;
|
||||
});
|
||||
await this.emailAddAtt(c, list);
|
||||
|
||||
if (!latestEmail) {
|
||||
latestEmail = {
|
||||
@@ -477,17 +471,7 @@ const emailService = {
|
||||
count++
|
||||
}
|
||||
|
||||
const emailIds = list.map(item => item.emailId);
|
||||
|
||||
if (emailIds.length > 0) {
|
||||
|
||||
const attsList = await attService.selectByEmailIds(c, emailIds);
|
||||
|
||||
list.forEach(emailRow => {
|
||||
const atts = attsList.filter(attsRow => attsRow.emailId === emailRow.emailId);
|
||||
emailRow.attList = atts;
|
||||
});
|
||||
}
|
||||
await this.emailAddAtt(c, list);
|
||||
|
||||
return list;
|
||||
},
|
||||
@@ -539,8 +523,8 @@ const emailService = {
|
||||
emailId = Number(emailId);
|
||||
timeSort = Number(timeSort);
|
||||
|
||||
if (size > 30) {
|
||||
size = 30;
|
||||
if (size > 50) {
|
||||
size = 50;
|
||||
}
|
||||
|
||||
if (!emailId) {
|
||||
@@ -555,6 +539,11 @@ const emailService = {
|
||||
|
||||
const conditions = [];
|
||||
|
||||
if (timeSort) {
|
||||
conditions.push(gt(email.emailId, emailId));
|
||||
} else {
|
||||
conditions.push(lt(email.emailId, emailId));
|
||||
}
|
||||
|
||||
if (type === 'send') {
|
||||
conditions.push(eq(email.type, emailConst.type.SEND));
|
||||
@@ -597,12 +586,6 @@ const emailService = {
|
||||
|
||||
const countConditions = [...conditions];
|
||||
|
||||
if (timeSort) {
|
||||
conditions.push(gt(email.emailId, emailId));
|
||||
} else {
|
||||
conditions.push(lt(email.emailId, emailId));
|
||||
}
|
||||
|
||||
const query = orm(c).select({ ...email, userEmail: user.email })
|
||||
.from(email)
|
||||
.leftJoin(user, eq(email.userId, user.userId))
|
||||
@@ -621,18 +604,69 @@ const emailService = {
|
||||
|
||||
const listQuery = await query.limit(size).all();
|
||||
const totalQuery = await queryCount.get();
|
||||
const latestEmailQuery = await orm(c).select().from(email)
|
||||
.where(and(
|
||||
eq(email.type, emailConst.type.RECEIVE),
|
||||
ne(email.status, emailConst.status.SAVING)
|
||||
))
|
||||
.orderBy(desc(email.emailId)).limit(1).get();
|
||||
|
||||
const [list, totalRow] = await Promise.all([listQuery, totalQuery]);
|
||||
let [list, totalRow, latestEmail] = await Promise.all([listQuery, totalQuery, latestEmailQuery]);
|
||||
|
||||
await this.emailAddAtt(c, list);
|
||||
|
||||
if (!latestEmail) {
|
||||
latestEmail = {
|
||||
emailId: 0,
|
||||
accountId: 0,
|
||||
userId: 0,
|
||||
}
|
||||
}
|
||||
|
||||
return { list: list, total: totalRow.total, latestEmail };
|
||||
},
|
||||
|
||||
async allEmailLatest(c, params) {
|
||||
|
||||
const { emailId } = params;
|
||||
|
||||
let count = 0
|
||||
let list = []
|
||||
|
||||
while ((count < 10) && list.length === 0) {
|
||||
list = await orm(c).select({...email, userEmail: user.email}).from(email)
|
||||
.leftJoin(user, eq(email.userId, user.userId))
|
||||
.where(
|
||||
and(
|
||||
gt(email.emailId, emailId),
|
||||
eq(email.type, emailConst.type.RECEIVE),
|
||||
ne(email.status, emailConst.status.SAVING)
|
||||
))
|
||||
.orderBy(desc(email.emailId))
|
||||
.limit(20);
|
||||
|
||||
await sleep(3000);
|
||||
count++
|
||||
}
|
||||
|
||||
await this.emailAddAtt(c, list);
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
async emailAddAtt(c, list) {
|
||||
|
||||
const emailIds = list.map(item => item.emailId);
|
||||
const attsList = await attService.selectByEmailIds(c, emailIds);
|
||||
|
||||
list.forEach(emailRow => {
|
||||
const atts = attsList.filter(attsRow => attsRow.emailId === emailRow.emailId);
|
||||
emailRow.attList = atts;
|
||||
});
|
||||
if (emailIds.length > 0) {
|
||||
|
||||
return { list: list, total: totalRow.total };
|
||||
const attsList = await attService.selectByEmailIds(c, emailIds);
|
||||
|
||||
list.forEach(emailRow => {
|
||||
const atts = attsList.filter(attsRow => attsRow.emailId === emailRow.emailId);
|
||||
emailRow.attList = atts;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async restoreByUserId(c, userId) {
|
||||
@@ -647,8 +681,8 @@ const emailService = {
|
||||
},
|
||||
|
||||
async completeReceiveAll(c) {
|
||||
await c.env.db.prepare(`UPDATE email as e SET status = ${emailConst.status.RECEIVE} WHERE status = ${emailConst.status.SAVING} AND EXISTS (SELECT 1 FROM account WHERE account_id = e.account_id)`).run();
|
||||
await c.env.db.prepare(`UPDATE email as e SET status = ${emailConst.status.NOONE} WHERE status = ${emailConst.status.SAVING} AND NOT EXISTS (SELECT 1 FROM account WHERE account_id = e.account_id)`).run();
|
||||
await c.env.db.prepare(`UPDATE email as e SET status = ${emailConst.status.RECEIVE} WHERE status = ${emailConst.status.SAVING} AND EXISTS (SELECT 1 FROM account WHERE account_id = e.account_id)`).run();
|
||||
await c.env.db.prepare(`UPDATE email as e SET status = ${emailConst.status.NOONE} WHERE status = ${emailConst.status.SAVING} AND NOT EXISTS (SELECT 1 FROM account WHERE account_id = e.account_id)`).run();
|
||||
},
|
||||
|
||||
async batchDelete(c, params) {
|
||||
|
||||
Reference in New Issue
Block a user