feat: update ev cli

This commit is contained in:
2025-05-18 17:59:54 +08:00
parent e9eedcd1bd
commit a05f2cd291
15 changed files with 484 additions and 585 deletions

View File

@@ -11,3 +11,13 @@ app
//
})
.addTo(app);
app
.route({
path: 'client',
key: 'version',
})
.define(async (ctx) => {
ctx.body = 'v1.0.0';
})
.addTo(app);

View File

@@ -0,0 +1,27 @@
import { QueryUtil } from '@kevisual/router/define';
export const shopDefine = QueryUtil.create({
getRegistry: {
path: 'shop',
key: 'get-registry',
description: '获取应用商店注册表信息',
},
listInstalled: {
path: 'shop',
key: 'list-installed',
description: '列出当前已安装的所有应用',
},
install: {
path: 'shop',
key: 'install',
description: '安装指定的应用,可以指定 id、type、force 和 yes 参数',
},
uninstall: {
path: 'shop',
key: 'uninstall',
description: '卸载指定的应用,可以指定 id 和 type 参数',
},
});

View File

@@ -1,64 +1,69 @@
import { app } from '@/app.ts';
// import { getInstallList, installApp, uninstallApp } from '@/modules/install.ts';
const getInstallList = async () => {
return [];
};
const installApp = async (pkg: string) => {
return {
code: 200,
message: 'success',
data: {
pkg,
},
};
};
const uninstallApp = async (pkg: string) => {
return {
code: 200,
message: 'success',
};
};
import { app, assistantConfig } from '@/app.ts';
import { AppDownload } from '@/services/app/index.ts';
import { AssistantApp } from '@/module/assistant/index.ts';
import { shopDefine } from './define.ts';
app
.route({
path: 'shop',
key: 'list-installed',
...shopDefine.get('getRegistry'),
middleware: ['auth'],
})
.define(async (ctx) => {
// https://localhost:51015/client/router?path=shop&key=list-installed
const list = await getInstallList();
ctx.body = list;
const registry = assistantConfig.getRegistry();
assistantConfig.checkMounted();
ctx.body = registry;
})
.addTo(app);
app
.route({
path: 'shop',
key: 'install',
...shopDefine.get('listInstalled'),
middleware: ['auth'],
})
.define(async (ctx) => {
const manager = new AssistantApp(assistantConfig);
await manager.loadConfig();
const data = await manager.getPageAndAppList();
ctx.body = data;
})
.addTo(app);
app
.route({
...shopDefine.get('install'),
middleware: ['auth'],
})
.define(async (ctx) => {
// https://localhost:51015/client/router?path=shop&key=install
const { pkg } = ctx.query.data;
const res = await installApp(pkg);
if (res.code !== 200) {
ctx.throw(res.code, res.message);
const options = ctx.query?.data || {};
const { id, type, force, yes } = options;
assistantConfig.checkMounted();
const registry = options.registry || assistantConfig.getRegistry();
// console.log('registry', registry);
const app = new AppDownload(assistantConfig);
let info = '';
if (id) {
const msg = await app.downloadApp({ id, type, registry, force, yes });
info = String(msg);
}
ctx.body = res;
ctx.body = { info };
})
.addTo(app);
app
.route({
path: 'shop',
key: 'uninstall',
...shopDefine.get('uninstall'),
middleware: ['auth'],
})
.define(async (ctx) => {
// https://localhost:51015/client/router?path=shop&key=uninstall
const { pkg } = ctx.query.data;
const res = await uninstallApp(pkg);
ctx.body = res;
const options = ctx.query?.data || {};
const { id, type, yes } = options;
const app = new AppDownload(assistantConfig);
let info = '';
if (id) {
const msg = await app.deleteApp({ id, type, yes });
info = String(msg);
}
ctx.body = { info };
})
.addTo(app);