54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { useContextKey } from "@kevisual/context";
|
|
import { app } from "../../app.ts";
|
|
import { AssistantApp } from "@/lib.ts";
|
|
|
|
app.route({
|
|
path: 'remote',
|
|
key: 'status',
|
|
middleware: ['auth-admin'],
|
|
description: '获取远程app连接状态',
|
|
}).define(async (ctx) => {
|
|
const manager = useContextKey('manager') as AssistantApp;
|
|
if (manager?.remoteApp?.isConnect()) {
|
|
const url = manager.remoteUrl || ''
|
|
ctx.body = {
|
|
content: `远程app已经链接, 访问地址:${url}`,
|
|
}
|
|
} else {
|
|
ctx.body = {
|
|
content: '远程app未连接',
|
|
}
|
|
}
|
|
}).addTo(app);
|
|
|
|
app.route({
|
|
path: 'remote',
|
|
key: 'connect',
|
|
middleware: ['auth-admin'],
|
|
description: '连接远程app',
|
|
}).define(async (ctx) => {
|
|
const manager = useContextKey('manager') as AssistantApp;
|
|
if (!manager) {
|
|
ctx.body = {
|
|
content: '远程app管理器未初始化',
|
|
}
|
|
return;
|
|
}
|
|
if (manager?.remoteApp?.isConnect()) {
|
|
const url = manager.remoteUrl || ''
|
|
ctx.body = {
|
|
content: `远程app已经链接, 访问地址:${url}`,
|
|
}
|
|
return;
|
|
}
|
|
await manager.initRemoteApp({ enabled: true, token: ctx.query?.token }).then(() => {
|
|
ctx.body = {
|
|
content: '远程app连接成功',
|
|
}
|
|
}).catch((err) => {
|
|
ctx.body = {
|
|
content: `远程app连接失败: ${err.message}`,
|
|
}
|
|
});
|
|
|
|
}).addTo(app); |