feat: init base module

This commit is contained in:
xion
2024-06-22 23:47:43 +08:00
commit 35f1182aec
18 changed files with 13328 additions and 0 deletions

45
src/admin/index.ts Normal file
View File

@@ -0,0 +1,45 @@
// admin 需要最后运行并在route中进行过滤。
import { Route } from '@abearxiong/router';
import { router } from '../modules/router.ts';
export const getRouterList = new Route('admin', 'getRouterList');
getRouterList.run = async (ctx) => {
// ctx.body = router.getList().filter((r) => r.path.startsWith('admin'));
ctx.body = router.getList().filter((r) => r.path.startsWith('admin'));
return ctx;
};
router.add(getRouterList);
// remove router
export const removeRouter = new Route('admin', 'removeRouter');
removeRouter.run = async (ctx) => {
const { path, key } = ctx.query;
router.remove({path, key});
ctx.body = 'success';
return ctx;
}
router.add(removeRouter);
// add router
export const addRouter = new Route('admin', 'addRouter');
addRouter.run = async (ctx) => {
const { path, key } = ctx.query;
router.add(new Route(path, key));
ctx.body = 'success';
return ctx;
}
router.add(addRouter);
// update router
export const updateRouter = new Route('admin', 'updateRouter');
updateRouter.run = async (ctx) => {
const { path, key } = ctx.query;
// router.update(path, key);
ctx.body = 'success';
return ctx;
}
router.add(updateRouter);