新增邮箱列表置顶排序

This commit is contained in:
eoao
2026-01-20 21:46:00 +08:00
parent cbae3ffbdf
commit 8a47418c91
8 changed files with 94 additions and 24 deletions

View File

@@ -27,3 +27,8 @@ app.put('/account/setAllReceive', async (c) => {
await accountService.setAllReceive(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
});
app.put('/account/setAsTop', async (c) => {
await accountService.setAsTop(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
});

View File

@@ -9,6 +9,7 @@ export const account = sqliteTable('account', {
createTime: text('create_time').default(sql`CURRENT_TIMESTAMP`),
userId: integer('user_id').notNull(),
allReceive: integer('all_receive').default(0).notNull(),
sort: integer('sort').default(0).notNull(),
isDel: integer('is_del').default(0).notNull(),
});
export default account

View File

@@ -26,10 +26,21 @@ const dbInit = {
await this.v2_5DB(c);
await this.v2_6DB(c);
await this.v2_7DB(c);
await this.v2_8DB(c);
await settingService.refresh(c);
return c.text('success');
},
async v2_8DB(c) {
try {
await c.env.db.batch([
c.env.db.prepare(`ALTER TABLE account ADD COLUMN sort INTEGER NOT NULL DEFAULT 0;`)
]);
} catch (e) {
console.warn(`跳过字段:${e.message}`);
}
},
async v2_7DB(c) {
try {
await c.env.db.batch([

View File

@@ -5,7 +5,7 @@ import userService from './user-service';
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 { and, asc, eq, gt, inArray, count, sql, ne, or, lt, desc } from 'drizzle-orm';
import {accountConst, isDel, settingConst} from '../const/entity-const';
import settingService from './setting-service';
import turnstileService from './turnstile-service';
@@ -105,10 +105,11 @@ const accountService = {
list(c, params, userId) {
let { accountId, size } = params;
let { accountId, size, lastSort } = params;
accountId = Number(accountId);
size = Number(size);
lastSort = Number(lastSort);
if (size > 30) {
size = 30;
@@ -117,12 +118,24 @@ const accountService = {
if (!accountId) {
accountId = 0;
}
if(Number.isNaN(lastSort)) {
lastSort = 9999999999;
}
return orm(c).select().from(account).where(
and(
eq(account.userId, userId),
eq(account.isDel, isDel.NORMAL),
gt(account.accountId, accountId)))
.orderBy(asc(account.accountId))
or(
lt(account.sort, lastSort),
and(
eq(account.sort, lastSort),
gt(account.accountId, accountId)
)
))
)
.orderBy(desc(account.sort), asc(account.accountId))
.limit(size)
.all();
},
@@ -242,6 +255,16 @@ const accountService = {
}
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();
},
async setAsTop(c, params, userId) {
const { accountId } = params;
console.log(accountId);
const userRow = await userService.selectById(c, userId);
const mainAccountRow = await accountService.selectByEmailIncludeDel(c, userRow.email);
let mainSort = mainAccountRow.sort === 0 ? 2 : mainAccountRow.sort + 1;
await orm(c).update(account).set({ sort: mainSort }).where(eq(account.email, userRow.email )).run();
await orm(c).update(account).set({ sort: mainSort - 1 }).where(and(eq(account.accountId, accountId),eq(account.userId,userId))).run();
}
};

View File

@@ -457,12 +457,12 @@ const emailService = {
)
.where(
and(
gt(email.emailId, emailId),
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)
eq(email.type, emailConst.type.RECEIVE)
))
.orderBy(desc(email.emailId))
.limit(20);