feat: 更新依赖版本,优化用户模型构造函数和域名管理路由

This commit is contained in:
2026-02-24 01:03:56 +08:00
parent 4b8f47cea8
commit 79e07d6689
5 changed files with 55 additions and 35 deletions

View File

@@ -67,8 +67,10 @@ export class User {
avatar: string;
tokenUser: any;
constructor(data: UserSelect) {
Object.assign(this, data);
constructor(data?: UserSelect) {
if (data) {
Object.assign(this, data);
}
}
setTokenUser(tokenUser: any) {
@@ -91,7 +93,7 @@ export class User {
exp: Math.floor(Date.now() / 1000) + expiresIn,
});
await oauth.setJwksToken(accessToken, { id: user.id, expire: expiresIn });
const token = {
accessToken,
refreshToken: accessToken,
@@ -99,7 +101,7 @@ export class User {
refreshTokenExpiresIn: expiresIn,
accessTokenExpiresIn: expiresIn,
};
return {
type: 'jwks',
...token,
@@ -150,9 +152,9 @@ export class User {
throw new CustomError('Invalid refresh token');
}
const decoded = await jwksManager.decode(jwsRefreshToken);
return await User.createJwksTokenResponse({
id: decoded.sub.replace('user:', ''),
username: decoded.name
return await User.createJwksTokenResponse({
id: decoded.sub.replace('user:', ''),
username: decoded.name
});
}
if (!refreshToken && !accessToken) {
@@ -212,9 +214,9 @@ export class User {
throw new CustomError('Invalid refresh token');
}
const decoded = await jwksManager.decode(refreshToken);
return await User.createJwksTokenResponse({
id: decoded.sub.replace('user:', ''),
username: decoded.name
return await User.createJwksTokenResponse({
id: decoded.sub.replace('user:', ''),
username: decoded.name
});
}
return await oauth.resetToken(refreshToken, expand);

View File

@@ -17,7 +17,7 @@ app
}
})
.define(async (ctx) => {
const { domain } = ctx.query.data;
const { domain } = ctx.args.data;
const domainInfos = await db.select().from(schema.kvAppDomain).where(eq(schema.kvAppDomain.domain, domain)).limit(1);
const domainInfo = domainInfos[0];
if (!domainInfo || !domainInfo.appId) {
@@ -38,11 +38,20 @@ app
path: 'app-domain',
key: 'create',
middleware: ['auth'],
description: '创建应用域名绑定',
metadata: {
args: {
data: z.object({
domain: z.string().describe('域名'),
appId: z.string().describe('应用ID'),
})
}
}
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const uid = tokenUser.uid;
const { domain, appId } = ctx.query.data || {};
const { domain, appId } = ctx.args.data || {};
if (!domain || !appId) {
ctx.throw(400, 'domain and appId are required');
}
@@ -58,11 +67,21 @@ app
path: 'app-domain',
key: 'update',
middleware: ['auth'],
metadata: {
args: {
data: z.object({
id: z.string().optional().describe('域名ID'),
domain: z.string().optional().describe('域名'),
appId: z.string().optional().describe('应用ID'),
status: z.string().describe('状态'),
})
}
}
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const uid = tokenUser.uid;
const { id, domain, appId, status } = ctx.query.data || {};
const { id, domain, appId, status } = ctx.args.data || {};
if (!domain && !id) {
ctx.throw(400, 'domain and id are required at least one');
}
@@ -87,7 +106,7 @@ app
if (domainInfo.uid !== uid) {
ctx.throw(403, 'domain must be owned by the user');
}
if (!AppDomainHelper.checkCanUpdateStatus(domainInfo.status!, status)) {
if (!AppDomainHelper.checkCanUpdateStatus(domainInfo.status!, status as any)) {
ctx.throw(400, 'domain status can not be updated');
}
const updateData: any = {};

View File

@@ -1,6 +1,5 @@
import { eq, desc, and, like, or } from 'drizzle-orm';
import { app, db, schema } from '../../app.ts';
import { CustomError } from '@kevisual/router';
import { filter } from '@kevisual/js-filter'
import { z } from 'zod';
app
@@ -77,7 +76,7 @@ app
const tokenUser = ctx.state.tokenUser;
const id = ctx.query.id;
if (!id) {
throw new CustomError('id is required');
ctx.throw(400, 'id is required');
}
const result = await db
.select()