feat(client): add routes for version, time, system info, and restart functionality
This commit is contained in:
84
assistant/src/routes/client/index.ts
Normal file
84
assistant/src/routes/client/index.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
import { app, assistantConfig } from '../../app.ts';
|
||||
import { createSkill } from '@kevisual/router';
|
||||
import os from 'node:os';
|
||||
import { runCommand } from '@/services/app/index.ts';
|
||||
app
|
||||
.route({
|
||||
path: 'client',
|
||||
key: 'version',
|
||||
description: '获取客户端版本号',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = 'v1.0.0';
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'client',
|
||||
key: 'time',
|
||||
description: '获取当前时间',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = {
|
||||
time: new Date().getTime(),
|
||||
date: new Date().toLocaleDateString(),
|
||||
};
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
// 调用 path: client key: system
|
||||
app
|
||||
.route({
|
||||
path: 'client',
|
||||
key: 'system',
|
||||
description: '获取系统信息',
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'view-system-info',
|
||||
title: '查看系统信息',
|
||||
summary: '获取服务器操作系统平台、架构和版本信息',
|
||||
})
|
||||
}
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { platform, arch, release } = os;
|
||||
ctx.body = {
|
||||
platform: platform(),
|
||||
arch: arch(),
|
||||
release: release(),
|
||||
};
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
||||
app.route({
|
||||
path: 'client',
|
||||
key: 'restart',
|
||||
description: '重启客户端',
|
||||
middleware: ['admin-auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'restart-client',
|
||||
title: '重启客户端',
|
||||
summary: '重启当前运行的客户端应用程序',
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const cmd = 'pm2 restart assistant-server --update-env';
|
||||
try {
|
||||
runCommand(cmd, []);
|
||||
ctx.body = {
|
||||
message: '客户端重启命令已执行',
|
||||
};
|
||||
} catch (error) {
|
||||
ctx.status = 500;
|
||||
ctx.body = {
|
||||
message: '重启客户端失败',
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user