import { app, assistantConfig } from '@/app.ts'; import { AppDownload } from '@/services/app/index.ts'; import { AssistantApp } from '@/module/assistant/index.ts'; app .route({ path: 'shop', key: 'get-registry', description: '获取应用商店注册表信息', middleware: ['auth-admin'], metadata: { admin: true, } }) .define(async (ctx) => { const registry = assistantConfig.getRegistry(); assistantConfig.checkMounted(); ctx.body = registry; }) .addTo(app); app .route({ path: 'shop', key: 'list-installed', description: '列出当前已安装的所有应用', middleware: ['auth-admin'], metadata: { admin: true, } }) .define(async (ctx) => { const manager = new AssistantApp(assistantConfig); await manager.loadConfig(); const data = await manager.getPageAndAppList(); ctx.body = data; }) .addTo(app); app .route({ path: 'shop', key: 'install', description: '安装指定的应用,可以指定 id、type、force 和 yes 参数', middleware: ['auth-admin'], metadata: { admin: true, } }) .define(async (ctx) => { // https://localhost:51515/client/router?path=shop&key=install 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 = { info }; }) .addTo(app); app .route({ path: 'shop', key: 'uninstall', description: '卸载指定的应用,可以指定 id 和 type 参数', middleware: ['auth-admin'], metadata: { admin: true, } }) .define(async (ctx) => { // https://localhost:51515/client/router?path=shop&key=uninstall 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);