chore: 更新依赖版本,提升 @kevisual/query 和 @kevisual/context 的版本
feat: 在应用管理路由中添加元数据,增强版本检测和发布功能
This commit is contained in:
@@ -8,6 +8,7 @@ import { User } from '@/models/user.ts';
|
||||
import { callDetectAppVersion } from './export.ts';
|
||||
import { eq, and, desc } from 'drizzle-orm';
|
||||
import { z } from 'zod';
|
||||
import { logger } from '@/modules/logger.ts';
|
||||
app
|
||||
.route({
|
||||
path: 'app',
|
||||
@@ -105,7 +106,7 @@ app
|
||||
if (!appListModel) {
|
||||
ctx.throw('app not found');
|
||||
}
|
||||
console.log('get app', appListModel.id, appListModel.key, appListModel.version);
|
||||
logger.debug('get app', appListModel.id, appListModel.key, appListModel.version);
|
||||
ctx.body = prefixFix(appListModel, tokenUser.username);
|
||||
})
|
||||
.addTo(app);
|
||||
@@ -289,6 +290,17 @@ app
|
||||
key: 'publish',
|
||||
middleware: ['auth'],
|
||||
description: '发布应用,将某个版本的应用设置为当前应用的版本',
|
||||
metadata: {
|
||||
args: {
|
||||
data: z.object({
|
||||
id: z.string().optional().describe('应用版本记录id'),
|
||||
username: z.string().optional().describe('用户名,默认为当前用户'),
|
||||
appKey: z.string().optional().describe('应用的唯一标识'),
|
||||
version: z.string().describe('应用版本'),
|
||||
detect: z.boolean().optional().describe('是否自动检测版本列表,默认false'),
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
@@ -346,8 +358,9 @@ app
|
||||
if (!am) {
|
||||
ctx.throw('app 未发现');
|
||||
}
|
||||
if (!isDetect) {
|
||||
const amData = am.data as AppData;
|
||||
const amData = am.data as AppData;
|
||||
if (version !== am.version) {
|
||||
// 发布版本和当前版本不一致
|
||||
await db.update(schema.kvApp)
|
||||
.set({ data: { ...amData, files }, version: appList.version, updatedAt: new Date().toISOString() })
|
||||
.where(eq(schema.kvApp.id, am.id));
|
||||
@@ -413,8 +426,17 @@ app
|
||||
.route({
|
||||
path: 'app',
|
||||
key: 'detectVersionList',
|
||||
description: '检测版本列表,minio中的数据自己上传后,根据版本信息,进行替换',
|
||||
description: '检测版本列表, 对存储内容的网关暴露对应的的模块',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
args: {
|
||||
data: z.object({
|
||||
appKey: z.string().describe('应用的唯一标识'),
|
||||
version: z.string().describe('应用版本'),
|
||||
username: z.string().optional().describe('用户名,默认为当前用户'),
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
@@ -469,6 +491,7 @@ app
|
||||
)).limit(1);
|
||||
let am = ams[0];
|
||||
if (!am) {
|
||||
// 如果应用不存在,则创建应用记录,版本为0.0.1
|
||||
const newAms = await db.insert(schema.kvApp).values({
|
||||
title: appKey,
|
||||
key: appKey,
|
||||
@@ -480,6 +503,7 @@ app
|
||||
}).returning();
|
||||
am = newAms[0];
|
||||
} else {
|
||||
// 如果应用存在,并且版本相同,则更新应用记录的文件列表
|
||||
const appModels = await db.select().from(schema.kvApp).where(and(
|
||||
eq(schema.kvApp.key, appKey),
|
||||
eq(schema.kvApp.version, version),
|
||||
|
||||
Reference in New Issue
Block a user