2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-06 12:27:13 +08:00

refactor: 面板websocket

This commit is contained in:
耗子
2024-10-20 22:14:11 +08:00
parent 892f91be3e
commit ff239c467a
14 changed files with 320 additions and 214 deletions

24
web/src/api/ws/index.ts Normal file
View File

@@ -0,0 +1,24 @@
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'
const base = `${protocol}://${window.location.host}/api/ws/`
export default {
// 执行命令
exec: (cmd: string): Promise<WebSocket> => {
return new Promise((resolve, reject) => {
const ws = new WebSocket(base + 'exec')
ws.onopen = () => {
ws.send(cmd)
resolve(ws)
}
ws.onerror = (e) => reject(e)
})
},
// 连接SSH
ssh: (): Promise<WebSocket> => {
return new Promise((resolve, reject) => {
const ws = new WebSocket(base + 'ssh')
ws.onopen = () => resolve(ws)
ws.onerror = (e) => reject(e)
})
}
}