Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-02-18 12:59:51 +08:00
parent 9cc48821b1
commit 577b6bfaa4
7 changed files with 1217 additions and 24 deletions

1163
bun.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -49,7 +49,7 @@
"@kevisual/ai": "^0.0.24",
"@kevisual/auth": "^2.0.3",
"@kevisual/js-filter": "^0.0.5",
"@kevisual/query": "^0.0.46",
"@kevisual/query": "^0.0.48",
"@types/busboy": "^1.5.4",
"@types/send": "^1.2.1",
"@types/ws": "^8.18.1",
@@ -59,21 +59,19 @@
"drizzle-orm": "^0.45.1",
"drizzle-zod": "^0.8.3",
"eventemitter3": "^5.0.4",
"pg": "^8.18.0",
"pm2": "^6.0.14",
"send": "^1.2.1",
"ws": "npm:@kevisual/ws",
"xml2js": "^0.6.2"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.992.0",
"@kevisual/api": "^0.0.51",
"@kevisual/api": "^0.0.52",
"@kevisual/context": "^0.0.6",
"@kevisual/local-app-manager": "0.1.32",
"@kevisual/logger": "^0.0.4",
"@kevisual/oss": "0.0.19",
"@kevisual/permission": "^0.0.4",
"@kevisual/router": "0.0.75",
"@kevisual/router": "0.0.80",
"@kevisual/types": "^0.0.12",
"@kevisual/use-config": "^1.0.30",
"@types/archiver": "^7.0.0",
@@ -102,5 +100,8 @@
"inflight": "latest",
"picomatch": "^4.0.2"
},
"packageManager": "pnpm@10.30.0"
"packageManager": "pnpm@10.30.0",
"workspaces": [
"wxmsg"
]
}

View File

@@ -1,13 +1,20 @@
import { app, db, schema } from '@/app.ts';
import { App, AppData } from '../module/app-drizzle.ts';
import { AppDomain, AppDomainHelper } from '../module/app-domain-drizzle.ts';
import { eq, and } from 'drizzle-orm';
import { randomUUID } from 'crypto';
import z from 'zod';
app
.route({
path: 'app',
key: 'getDomainApp',
description: '根据域名获取应用信息',
metadata: {
args: {
data: z.object({
domain: z.string().describe('域名'),
})
}
}
})
.define(async (ctx) => {
const { domain } = ctx.query.data;
@@ -39,7 +46,7 @@ app
if (!domain || !appId) {
ctx.throw(400, 'domain and appId are required');
}
const newDomains = await db.insert(schema.kvAppDomain).values({ id: randomUUID(), domain, appId, uid }).returning();
const newDomains = await db.insert(schema.kvAppDomain).values({ domain, appId, uid }).returning();
const domainInfo = newDomains[0];
ctx.body = domainInfo;
return ctx;

View File

@@ -1,7 +1,6 @@
import { app, db, schema } from '@/app.ts';
import { AppDomain, AppDomainHelper } from '../module/app-domain-drizzle.ts';
import { eq } from 'drizzle-orm';
import { randomUUID } from 'crypto';
import z from 'zod';
app
@@ -78,7 +77,7 @@ app
try {
if (!domainInfo) {
await checkAppId();
const newDomains = await db.insert(schema.kvAppDomain).values({ id: randomUUID(), domain, data: {}, ...rest }).returning();
const newDomains = await db.insert(schema.kvAppDomain).values({ domain, data: {}, ...rest }).returning();
domainInfo = newDomains[0];
} else {
if (rest.status && domainInfo.status !== rest.status) {

View File

@@ -7,7 +7,6 @@ import { setExpire } from './revoke.ts';
import { User } from '@/models/user.ts';
import { callDetectAppVersion } from './export.ts';
import { eq, and, desc } from 'drizzle-orm';
import { randomUUID } from 'crypto';
import { z } from 'zod';
app
.route({
@@ -70,7 +69,6 @@ app
}
if (!appListModel && create) {
const newApps = await db.insert(schema.kvAppList).values({
id: randomUUID(),
key,
version,
uid: tokenUser.id,
@@ -84,7 +82,6 @@ app
const appModel = appModels[0];
if (!appModel) {
await db.insert(schema.kvApp).values({
id: randomUUID(),
key,
uid: tokenUser.id,
user: tokenUser.username,
@@ -145,7 +142,7 @@ app
if (!rest.key) {
ctx.throw('key is required');
}
const newApps = await db.insert(schema.kvAppList).values({ id: randomUUID(), data, ...rest, uid: tokenUser.id }).returning();
const newApps = await db.insert(schema.kvAppList).values({ data, ...rest, uid: tokenUser.id }).returning();
ctx.body = newApps[0];
return ctx;
})
@@ -233,7 +230,6 @@ app
if (!am) {
appIsNew = true;
const newAms = await db.insert(schema.kvApp).values({
id: randomUUID(),
user: userPrefix,
key: appKey,
uid,
@@ -255,7 +251,6 @@ app
let app = apps[0];
if (!app) {
const newApps = await db.insert(schema.kvAppList).values({
id: randomUUID(),
key: appKey,
version,
uid: uid,
@@ -436,7 +431,6 @@ app
let appList = appLists[0];
if (!appList) {
const newAppLists = await db.insert(schema.kvAppList).values({
id: randomUUID(),
key: appKey,
version,
uid,

View File

@@ -1,5 +1,4 @@
import { app, db, schema } from '@/app.ts';
import { randomUUID } from 'crypto';
import { oss } from '@/app.ts';
import { User } from '@/models/user.ts';
import { customAlphabet } from 'nanoid';
@@ -10,9 +9,7 @@ const number = '0123456789';
const randomId = customAlphabet(letter + number, 16);
const getShareUser = async () => {
const shareUser = await User.findOne({
where: {
username: 'share',
},
});
return shareUser?.id || '';
};
@@ -64,7 +61,6 @@ app
},
];
const appModels = await db.insert(schema.kvApp).values({
id: randomUUID(),
title,
description,
version,
@@ -82,7 +78,6 @@ app
}).returning();
const appModel = appModels[0];
const appVersionModels = await db.insert(schema.kvAppList).values({
id: randomUUID(),
data: {
files: files,
},

View File

@@ -3,6 +3,7 @@ import { app, db, schema } from '@/app.ts';
import { setExpire } from './revoke.ts';
import { deleteFileByPrefix } from '../file/index.ts';
import { eq, and, desc } from 'drizzle-orm';
import z from 'zod';
app
.route({
@@ -42,6 +43,14 @@ app
key: 'get',
middleware: ['auth'],
description: '获取用户应用,可以指定id或者key',
metadata: {
args: {
id: z.string().optional(),
data: z.object({
key: z.string().optional(),
}).optional(),
}
}
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -79,6 +88,20 @@ app
key: 'update',
middleware: ['auth'],
description: '创建或更新用户应用参数在data中传入',
metadata: {
args: {
data: z.object({
id: z.string().optional(),
key: z.string().optional(),
title: z.string().optional(),
description: z.string().optional(),
version: z.string().optional(),
proxy: z.boolean().optional(),
share: z.boolean().optional(),
status: z.enum(['running', 'stopped']).optional(),
}),
}
}
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -138,6 +161,12 @@ app
key: 'delete',
middleware: ['auth'],
description: '删除用户应用可以指定id参数deleteFile表示是否删除文件默认不删除',
metadata: {
args: {
id: z.string().optional().describe('应用id'),
deleteFile: z.boolean().optional().describe('是否删除文件, 默认不删除'),
}
}
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -172,6 +201,11 @@ app
path: 'user-app',
key: 'test',
description: '对user-app的数据进行测试, 获取版本的信息',
metadata: {
args: {
id: z.string().optional().describe('应用id'),
}
}
})
.define(async (ctx) => {
const id = ctx.query.id;