Refactor code structure for improved readability and maintainability
This commit is contained in:
13
package.json
13
package.json
@@ -49,7 +49,7 @@
|
|||||||
"@kevisual/ai": "^0.0.24",
|
"@kevisual/ai": "^0.0.24",
|
||||||
"@kevisual/auth": "^2.0.3",
|
"@kevisual/auth": "^2.0.3",
|
||||||
"@kevisual/js-filter": "^0.0.5",
|
"@kevisual/js-filter": "^0.0.5",
|
||||||
"@kevisual/query": "^0.0.46",
|
"@kevisual/query": "^0.0.48",
|
||||||
"@types/busboy": "^1.5.4",
|
"@types/busboy": "^1.5.4",
|
||||||
"@types/send": "^1.2.1",
|
"@types/send": "^1.2.1",
|
||||||
"@types/ws": "^8.18.1",
|
"@types/ws": "^8.18.1",
|
||||||
@@ -59,21 +59,19 @@
|
|||||||
"drizzle-orm": "^0.45.1",
|
"drizzle-orm": "^0.45.1",
|
||||||
"drizzle-zod": "^0.8.3",
|
"drizzle-zod": "^0.8.3",
|
||||||
"eventemitter3": "^5.0.4",
|
"eventemitter3": "^5.0.4",
|
||||||
"pg": "^8.18.0",
|
|
||||||
"pm2": "^6.0.14",
|
|
||||||
"send": "^1.2.1",
|
"send": "^1.2.1",
|
||||||
"ws": "npm:@kevisual/ws",
|
"ws": "npm:@kevisual/ws",
|
||||||
"xml2js": "^0.6.2"
|
"xml2js": "^0.6.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.992.0",
|
"@aws-sdk/client-s3": "^3.992.0",
|
||||||
"@kevisual/api": "^0.0.51",
|
"@kevisual/api": "^0.0.52",
|
||||||
"@kevisual/context": "^0.0.6",
|
"@kevisual/context": "^0.0.6",
|
||||||
"@kevisual/local-app-manager": "0.1.32",
|
"@kevisual/local-app-manager": "0.1.32",
|
||||||
"@kevisual/logger": "^0.0.4",
|
"@kevisual/logger": "^0.0.4",
|
||||||
"@kevisual/oss": "0.0.19",
|
"@kevisual/oss": "0.0.19",
|
||||||
"@kevisual/permission": "^0.0.4",
|
"@kevisual/permission": "^0.0.4",
|
||||||
"@kevisual/router": "0.0.75",
|
"@kevisual/router": "0.0.80",
|
||||||
"@kevisual/types": "^0.0.12",
|
"@kevisual/types": "^0.0.12",
|
||||||
"@kevisual/use-config": "^1.0.30",
|
"@kevisual/use-config": "^1.0.30",
|
||||||
"@types/archiver": "^7.0.0",
|
"@types/archiver": "^7.0.0",
|
||||||
@@ -102,5 +100,8 @@
|
|||||||
"inflight": "latest",
|
"inflight": "latest",
|
||||||
"picomatch": "^4.0.2"
|
"picomatch": "^4.0.2"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@10.30.0"
|
"packageManager": "pnpm@10.30.0",
|
||||||
|
"workspaces": [
|
||||||
|
"wxmsg"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
import { app, db, schema } from '@/app.ts';
|
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 { AppDomain, AppDomainHelper } from '../module/app-domain-drizzle.ts';
|
||||||
import { eq, and } from 'drizzle-orm';
|
import { eq, and } from 'drizzle-orm';
|
||||||
import { randomUUID } from 'crypto';
|
import z from 'zod';
|
||||||
|
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
key: 'getDomainApp',
|
key: 'getDomainApp',
|
||||||
|
description: '根据域名获取应用信息',
|
||||||
|
metadata: {
|
||||||
|
args: {
|
||||||
|
data: z.object({
|
||||||
|
domain: z.string().describe('域名'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const { domain } = ctx.query.data;
|
const { domain } = ctx.query.data;
|
||||||
@@ -39,7 +46,7 @@ app
|
|||||||
if (!domain || !appId) {
|
if (!domain || !appId) {
|
||||||
ctx.throw(400, 'domain and appId are required');
|
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];
|
const domainInfo = newDomains[0];
|
||||||
ctx.body = domainInfo;
|
ctx.body = domainInfo;
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { app, db, schema } from '@/app.ts';
|
import { app, db, schema } from '@/app.ts';
|
||||||
import { AppDomain, AppDomainHelper } from '../module/app-domain-drizzle.ts';
|
import { AppDomain, AppDomainHelper } from '../module/app-domain-drizzle.ts';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
|
|
||||||
app
|
app
|
||||||
@@ -78,7 +77,7 @@ app
|
|||||||
try {
|
try {
|
||||||
if (!domainInfo) {
|
if (!domainInfo) {
|
||||||
await checkAppId();
|
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];
|
domainInfo = newDomains[0];
|
||||||
} else {
|
} else {
|
||||||
if (rest.status && domainInfo.status !== rest.status) {
|
if (rest.status && domainInfo.status !== rest.status) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { setExpire } from './revoke.ts';
|
|||||||
import { User } from '@/models/user.ts';
|
import { User } from '@/models/user.ts';
|
||||||
import { callDetectAppVersion } from './export.ts';
|
import { callDetectAppVersion } from './export.ts';
|
||||||
import { eq, and, desc } from 'drizzle-orm';
|
import { eq, and, desc } from 'drizzle-orm';
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
@@ -70,7 +69,6 @@ app
|
|||||||
}
|
}
|
||||||
if (!appListModel && create) {
|
if (!appListModel && create) {
|
||||||
const newApps = await db.insert(schema.kvAppList).values({
|
const newApps = await db.insert(schema.kvAppList).values({
|
||||||
id: randomUUID(),
|
|
||||||
key,
|
key,
|
||||||
version,
|
version,
|
||||||
uid: tokenUser.id,
|
uid: tokenUser.id,
|
||||||
@@ -84,7 +82,6 @@ app
|
|||||||
const appModel = appModels[0];
|
const appModel = appModels[0];
|
||||||
if (!appModel) {
|
if (!appModel) {
|
||||||
await db.insert(schema.kvApp).values({
|
await db.insert(schema.kvApp).values({
|
||||||
id: randomUUID(),
|
|
||||||
key,
|
key,
|
||||||
uid: tokenUser.id,
|
uid: tokenUser.id,
|
||||||
user: tokenUser.username,
|
user: tokenUser.username,
|
||||||
@@ -145,7 +142,7 @@ app
|
|||||||
if (!rest.key) {
|
if (!rest.key) {
|
||||||
ctx.throw('key is required');
|
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];
|
ctx.body = newApps[0];
|
||||||
return ctx;
|
return ctx;
|
||||||
})
|
})
|
||||||
@@ -233,7 +230,6 @@ app
|
|||||||
if (!am) {
|
if (!am) {
|
||||||
appIsNew = true;
|
appIsNew = true;
|
||||||
const newAms = await db.insert(schema.kvApp).values({
|
const newAms = await db.insert(schema.kvApp).values({
|
||||||
id: randomUUID(),
|
|
||||||
user: userPrefix,
|
user: userPrefix,
|
||||||
key: appKey,
|
key: appKey,
|
||||||
uid,
|
uid,
|
||||||
@@ -255,7 +251,6 @@ app
|
|||||||
let app = apps[0];
|
let app = apps[0];
|
||||||
if (!app) {
|
if (!app) {
|
||||||
const newApps = await db.insert(schema.kvAppList).values({
|
const newApps = await db.insert(schema.kvAppList).values({
|
||||||
id: randomUUID(),
|
|
||||||
key: appKey,
|
key: appKey,
|
||||||
version,
|
version,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@@ -436,7 +431,6 @@ app
|
|||||||
let appList = appLists[0];
|
let appList = appLists[0];
|
||||||
if (!appList) {
|
if (!appList) {
|
||||||
const newAppLists = await db.insert(schema.kvAppList).values({
|
const newAppLists = await db.insert(schema.kvAppList).values({
|
||||||
id: randomUUID(),
|
|
||||||
key: appKey,
|
key: appKey,
|
||||||
version,
|
version,
|
||||||
uid,
|
uid,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { app, db, schema } from '@/app.ts';
|
import { app, db, schema } from '@/app.ts';
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { oss } from '@/app.ts';
|
import { oss } from '@/app.ts';
|
||||||
import { User } from '@/models/user.ts';
|
import { User } from '@/models/user.ts';
|
||||||
import { customAlphabet } from 'nanoid';
|
import { customAlphabet } from 'nanoid';
|
||||||
@@ -10,9 +9,7 @@ const number = '0123456789';
|
|||||||
const randomId = customAlphabet(letter + number, 16);
|
const randomId = customAlphabet(letter + number, 16);
|
||||||
const getShareUser = async () => {
|
const getShareUser = async () => {
|
||||||
const shareUser = await User.findOne({
|
const shareUser = await User.findOne({
|
||||||
where: {
|
username: 'share',
|
||||||
username: 'share',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
return shareUser?.id || '';
|
return shareUser?.id || '';
|
||||||
};
|
};
|
||||||
@@ -64,7 +61,6 @@ app
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
const appModels = await db.insert(schema.kvApp).values({
|
const appModels = await db.insert(schema.kvApp).values({
|
||||||
id: randomUUID(),
|
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
version,
|
version,
|
||||||
@@ -82,7 +78,6 @@ app
|
|||||||
}).returning();
|
}).returning();
|
||||||
const appModel = appModels[0];
|
const appModel = appModels[0];
|
||||||
const appVersionModels = await db.insert(schema.kvAppList).values({
|
const appVersionModels = await db.insert(schema.kvAppList).values({
|
||||||
id: randomUUID(),
|
|
||||||
data: {
|
data: {
|
||||||
files: files,
|
files: files,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { app, db, schema } from '@/app.ts';
|
|||||||
import { setExpire } from './revoke.ts';
|
import { setExpire } from './revoke.ts';
|
||||||
import { deleteFileByPrefix } from '../file/index.ts';
|
import { deleteFileByPrefix } from '../file/index.ts';
|
||||||
import { eq, and, desc } from 'drizzle-orm';
|
import { eq, and, desc } from 'drizzle-orm';
|
||||||
|
import z from 'zod';
|
||||||
|
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
@@ -42,6 +43,14 @@ app
|
|||||||
key: 'get',
|
key: 'get',
|
||||||
middleware: ['auth'],
|
middleware: ['auth'],
|
||||||
description: '获取用户应用,可以指定id或者key',
|
description: '获取用户应用,可以指定id或者key',
|
||||||
|
metadata: {
|
||||||
|
args: {
|
||||||
|
id: z.string().optional(),
|
||||||
|
data: z.object({
|
||||||
|
key: z.string().optional(),
|
||||||
|
}).optional(),
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const tokenUser = ctx.state.tokenUser;
|
const tokenUser = ctx.state.tokenUser;
|
||||||
@@ -79,6 +88,20 @@ app
|
|||||||
key: 'update',
|
key: 'update',
|
||||||
middleware: ['auth'],
|
middleware: ['auth'],
|
||||||
description: '创建或更新用户应用,参数在data中传入',
|
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) => {
|
.define(async (ctx) => {
|
||||||
const tokenUser = ctx.state.tokenUser;
|
const tokenUser = ctx.state.tokenUser;
|
||||||
@@ -138,6 +161,12 @@ app
|
|||||||
key: 'delete',
|
key: 'delete',
|
||||||
middleware: ['auth'],
|
middleware: ['auth'],
|
||||||
description: '删除用户应用,可以指定id,参数:deleteFile表示是否删除文件,默认不删除',
|
description: '删除用户应用,可以指定id,参数:deleteFile表示是否删除文件,默认不删除',
|
||||||
|
metadata: {
|
||||||
|
args: {
|
||||||
|
id: z.string().optional().describe('应用id'),
|
||||||
|
deleteFile: z.boolean().optional().describe('是否删除文件, 默认不删除'),
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const tokenUser = ctx.state.tokenUser;
|
const tokenUser = ctx.state.tokenUser;
|
||||||
@@ -172,6 +201,11 @@ app
|
|||||||
path: 'user-app',
|
path: 'user-app',
|
||||||
key: 'test',
|
key: 'test',
|
||||||
description: '对user-app的数据进行测试, 获取版本的信息',
|
description: '对user-app的数据进行测试, 获取版本的信息',
|
||||||
|
metadata: {
|
||||||
|
args: {
|
||||||
|
id: z.string().optional().describe('应用id'),
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const id = ctx.query.id;
|
const id = ctx.query.id;
|
||||||
|
|||||||
Reference in New Issue
Block a user