feat: WebSSH 上传下载文件 (by trzsz)

This commit is contained in:
naiba
2024-08-13 00:30:18 +08:00
parent 2083512607
commit f4d9db28a2
7 changed files with 95 additions and 12 deletions
+9
View File
@@ -0,0 +1,9 @@
package pty
type IPty interface {
Write(p []byte) (n int, err error)
Read(p []byte) (n int, err error)
Getsize() (uint16, uint16, error)
Setsize(cols, rows uint32) error
Close() error
}
+11 -1
View File
@@ -22,7 +22,7 @@ type Pty struct {
func DownloadDependency() {
}
func Start() (*Pty, error) {
func Start() (IPty, error) {
var shellPath string
for i := 0; i < len(defaultShells); i++ {
shellPath, _ = exec.LookPath(defaultShells[i])
@@ -47,6 +47,14 @@ func (pty *Pty) Read(p []byte) (n int, err error) {
return pty.tty.Read(p)
}
func (pty *Pty) Getsize() (uint16, uint16, error) {
ws, err := opty.GetsizeFull(pty.tty)
if err != nil {
return 0, 0, err
}
return ws.Cols, ws.Rows, nil
}
func (pty *Pty) Setsize(cols, rows uint32) error {
return opty.Setsize(pty.tty, &opty.Winsize{
Cols: uint16(cols),
@@ -71,3 +79,5 @@ func (pty *Pty) Close() error {
}
return pty.killChildProcess(pty.cmd)
}
var _ IPty = &Pty{}
+12 -8
View File
@@ -22,13 +22,6 @@ import (
var isWin10 bool
type Pty interface {
Write(p []byte) (n int, err error)
Read(p []byte) (n int, err error)
Setsize(cols, rows uint32) error
Close() error
}
type winPTY struct {
tty *winpty.WinPTY
}
@@ -118,7 +111,7 @@ func getExecutableFilePath() (string, error) {
return filepath.Dir(ex), nil
}
func Start() (Pty, error) {
func Start() (IPty, error) {
shellPath, err := exec.LookPath("powershell.exe")
if err != nil || shellPath == "" {
shellPath = "cmd.exe"
@@ -143,6 +136,10 @@ func (w *winPTY) Read(p []byte) (n int, err error) {
return w.tty.StdOut.Read(p)
}
func (w *winPTY) Getsize() (uint16, uint16, error) {
return 80, 40, nil
}
func (w *winPTY) Setsize(cols, rows uint32) error {
w.tty.SetSize(cols, rows)
return nil
@@ -161,6 +158,10 @@ func (c *conPty) Read(p []byte) (n int, err error) {
return c.tty.Read(p)
}
func (c *conPty) Getsize() (uint16, uint16, error) {
return 80, 40, nil
}
func (c *conPty) Setsize(cols, rows uint32) error {
c.tty.Resize(int(cols), int(rows))
return nil
@@ -172,3 +173,6 @@ func (c *conPty) Close() error {
}
return nil
}
var _ IPty = &winPTY{}
var _ IPty = &conPty{}
+7 -1
View File
@@ -25,7 +25,7 @@ func getExecutableFilePath() (string, error) {
return filepath.Dir(ex), nil
}
func Start() (*Pty, error) {
func Start() (IPty, error) {
shellPath, err := exec.LookPath("powershell.exe")
if err != nil || shellPath == "" {
shellPath = "cmd.exe"
@@ -46,6 +46,10 @@ func (pty *Pty) Read(p []byte) (n int, err error) {
return pty.tty.Read(p)
}
func (pty *Pty) Getsize() (uint16, uint16, error) {
return 80, 40, nil
}
func (pty *Pty) Setsize(cols, rows uint32) error {
return pty.tty.Resize(int(cols), int(rows))
}
@@ -56,3 +60,5 @@ func (pty *Pty) Close() error {
}
return nil
}
var _ IPty = &Pty{}