2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-05 06:57:19 +08:00
Files
panel/web/src/api/ws/index.ts
2024-10-23 02:39:43 +08:00

25 lines
675 B
Go

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: (id: number): Promise<WebSocket> => {
return new Promise((resolve, reject) => {
const ws = new WebSocket(`${base}/ssh?id=${id}`)
ws.onopen = () => resolve(ws)
ws.onerror = (e) => reject(e)
})
}
}