feat(cnb-board): add cnb-dev-env routes and related functionalities
- Implemented routes for cnb-board to fetch live environment configurations, repository info, build info, pull request info, NPC info, and comment info. - Created a utility function to execute shell commands. - Added a check to determine if the environment is a CNB environment. - Introduced a method to retrieve live markdown content with detailed service access information. - Enhanced system information retrieval with CPU, memory, and disk usage metrics. - Established a module structure for better organization of cnb-board related functionalities.
This commit is contained in:
38
agent/routes/cnb-board/index.ts
Normal file
38
agent/routes/cnb-board/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { app } from '../../app.ts';
|
||||
import './cnb-dev-env.ts';
|
||||
import { useKey } from '@kevisual/context';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
export const execCommand = (command: string, options: { cwd?: string } = {}) => {
|
||||
const { cwd } = options;
|
||||
return spawnSync(command, {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
cwd: cwd,
|
||||
env: process.env,
|
||||
});
|
||||
};
|
||||
app.route({
|
||||
path: 'cnb-board',
|
||||
key: 'is-cnb-board',
|
||||
description: '检查是否是 cnb-board 环境',
|
||||
middleware: ['auth-admin']
|
||||
}).define(async (ctx) => {
|
||||
const isCNB = useKey('CNB');
|
||||
ctx.body = {
|
||||
isCNB: !!isCNB,
|
||||
};
|
||||
}).addTo(app);
|
||||
|
||||
|
||||
|
||||
|
||||
app.route({
|
||||
path: 'cnb-board',
|
||||
key: 'exit',
|
||||
description: 'cnb的工作环境退出程序',
|
||||
middleware: ['auth-admin'],
|
||||
}).define(async (ctx) => {
|
||||
const cmd = 'kill 1';
|
||||
execCommand(cmd);
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user