新增显示所有邮箱邮件

This commit is contained in:
eoao
2025-12-07 22:08:00 +08:00
parent 9ec5345309
commit 13abc11f2c
21 changed files with 184 additions and 48 deletions
+5
View File
@@ -22,3 +22,8 @@ app.put('/account/setName', async (c) => {
await accountService.setName(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
});
app.put('/account/setAllReceive', async (c) => {
await accountService.setAllReceive(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
});
+7
View File
@@ -7,6 +7,13 @@ export const userConst = {
}
}
export const accountConst = {
allReceive: {
CLOSE: 0,
OPEN: 1
}
}
export const roleConst = {
isDefault: {
CLOSE: 0,
+1
View File
@@ -8,6 +8,7 @@ export const account = sqliteTable('account', {
latestEmailTime: text('latest_email_time'),
createTime: text('create_time').default(sql`CURRENT_TIMESTAMP`),
userId: integer('user_id').notNull(),
allReceive: integer('all_receive').default(0).notNull(),
isDel: integer('is_del').default(0).notNull(),
});
export default account
+9
View File
@@ -25,10 +25,19 @@ const init = {
await this.v2_3DB(c);
await this.v2_4DB(c);
await this.v2_5DB(c);
await this.v2_6DB(c);
await settingService.refresh(c);
return c.text(t('initSuccess'));
},
async v2_6DB(c) {
try {
await c.env.db.prepare(`ALTER TABLE account ADD COLUMN all_receive INTEGER NOT NULL DEFAULT 0;`).run();
} catch (e) {
console.error(e)
}
},
async v2_5DB(c) {
try {
+12 -2
View File
@@ -6,7 +6,7 @@ import emailService from './email-service';
import orm from '../entity/orm';
import account from '../entity/account';
import { and, asc, eq, gt, inArray, count, sql, ne } from 'drizzle-orm';
import { isDel, settingConst } from '../const/entity-const';
import {accountConst, isDel, settingConst} from '../const/entity-const';
import settingService from './setting-service';
import turnstileService from './turnstile-service';
import roleService from './role-service';
@@ -231,8 +231,18 @@ const accountService = {
const { accountId } = params
await emailService.physicsDeleteByAccountId(c, accountId)
await orm(c).delete(account).where(eq(account.accountId, accountId)).run();
}
},
async setAllReceive(c, params, userId) {
let a = null
const { accountId } = params;
const accountRow = await this.selectById(c, accountId);
if (accountRow.userId !== userId) {
return;
}
await orm(c).update(account).set({ allReceive: accountConst.allReceive.CLOSE }).where(eq(account.userId, userId)).run();
await orm(c).update(account).set({ allReceive: accountRow.allReceive ? 0 : 1 }).where(eq(account.accountId, accountId)).run();
}
};
export default accountService;
+49 -20
View File
@@ -19,17 +19,19 @@ import kvConst from '../const/kv-const';
import { t } from '../i18n/i18n'
import r2Service from './r2-service';
import domainUtils from '../utils/domain-uitls';
import account from "../entity/account";
const emailService = {
async list(c, params, userId) {
let { emailId, type, accountId, size, timeSort } = params;
let { emailId, type, accountId, size, timeSort, allReceive } = params;
size = Number(size);
emailId = Number(emailId);
timeSort = Number(timeSort);
accountId = Number(accountId);
allReceive = Number(allReceive);
if (size > 30) {
size = 30;
@@ -45,6 +47,10 @@ const emailService = {
}
if (isNaN(allReceive)) {
let accountRow = await accountService.selectById(c, accountId);
allReceive = accountRow.allReceive;
}
const query = orm(c)
.select({
@@ -58,14 +64,18 @@ const emailService = {
eq(star.emailId, email.emailId),
eq(star.userId, userId)
)
).leftJoin(
account,
eq(account.accountId, email.accountId)
)
.where(
and(
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.accountId, accountId),
timeSort ? gt(email.emailId, emailId) : lt(email.emailId, emailId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL)
eq(email.isDel, isDel.NORMAL),
eq(account.isDel, isDel.NORMAL)
)
);
@@ -77,23 +87,29 @@ const emailService = {
const listQuery = query.limit(size).all();
const totalQuery = orm(c).select({ total: count() }).from(email).where(
and(
eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL)
const totalQuery = orm(c).select({ total: count() }).from(email)
.leftJoin(
account,
eq(account.accountId, email.accountId)
)
.where(
and(
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL),
eq(account.isDel, isDel.NORMAL)
)
).get();
const latestEmailQuery = orm(c).select().from(email).where(
and(
eq(email.accountId, accountId),
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL)
))
.orderBy(desc(email.emailId)).limit(1).get();
.orderBy(desc(email.emailId)).limit(size).get();
let [list, totalRow, latestEmail] = await Promise.all([listQuery, totalQuery, latestEmailQuery]);
@@ -445,15 +461,28 @@ const emailService = {
},
async latest(c, params, userId) {
let { emailId, accountId } = params;
const list = await orm(c).select().from(email).where(
and(
eq(email.userId, userId),
eq(email.isDel, isDel.NORMAL),
eq(email.accountId, accountId),
eq(email.type, emailConst.type.RECEIVE),
gt(email.emailId, emailId)
))
let { emailId, accountId, allReceive } = params;
allReceive = Number(allReceive);
if (isNaN(allReceive)) {
let accountRow = await accountService.selectById(c, accountId);
allReceive = accountRow.allReceive;
}
const list = await orm(c).select({...email}).from(email)
.leftJoin(
account,
eq(account.accountId, email.accountId)
)
.where(
and(
eq(email.userId, userId),
eq(email.isDel, isDel.NORMAL),
eq(account.isDel, isDel.NORMAL),
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.type, emailConst.type.RECEIVE),
gt(email.emailId, emailId)
))
.orderBy(desc(email.emailId))
.limit(20);