mirror of
https://github.com/acepanel/panel.git
synced 2026-02-06 12:27:13 +08:00
refactor: 面板websocket
This commit is contained in:
24
web/src/api/ws/index.ts
Normal file
24
web/src/api/ws/index.ts
Normal 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user