feat: add file transfer support (#55)

* feat: add file transfer support

* 1MB buffer
This commit is contained in:
UUBulb
2024-08-20 22:24:03 +08:00
committed by GitHub
parent 093275bc80
commit 73a727d435
9 changed files with 342 additions and 54 deletions
+2 -1
View File
@@ -19,7 +19,8 @@ type Pty struct {
cmd *exec.Cmd
}
func DownloadDependency() {
func DownloadDependency() error {
return nil
}
func Start() (IPty, error) {
+8 -13
View File
@@ -5,7 +5,6 @@ package pty
import (
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
@@ -55,12 +54,11 @@ func VersionCheck() bool {
return false
}
func DownloadDependency() {
func DownloadDependency() error {
if !isWin10 {
executablePath, err := getExecutableFilePath()
if err != nil {
fmt.Println("NEZHA>> wintty 获取文件路径失败", err)
return
return fmt.Errorf("winpty 获取文件路径失败: %v", err)
}
winptyAgentExe := filepath.Join(executablePath, "winpty-agent.exe")
@@ -69,27 +67,23 @@ func DownloadDependency() {
fe, errFe := os.Stat(winptyAgentExe)
fd, errFd := os.Stat(winptyAgentDll)
if errFe == nil && fe.Size() > 300000 && errFd == nil && fd.Size() > 300000 {
return
return fmt.Errorf("winpty 文件完整性检查失败")
}
resp, err := http.Get("https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip")
if err != nil {
log.Println("NEZHA>> wintty 下载失败", err)
return
return fmt.Errorf("winpty 下载失败: %v", err)
}
defer resp.Body.Close()
content, err := io.ReadAll(resp.Body)
if err != nil {
log.Println("NEZHA>> wintty 下载失败", err)
return
return fmt.Errorf("winpty 下载失败: %v", err)
}
if err := os.WriteFile("./wintty.zip", content, os.FileMode(0777)); err != nil {
log.Println("NEZHA>> wintty 写入失败", err)
return
return fmt.Errorf("winpty 写入失败: %v", err)
}
if err := unzip.New("./wintty.zip", "./wintty").Extract(); err != nil {
fmt.Println("NEZHA>> wintty 解压失败", err)
return
return fmt.Errorf("winpty 解压失败: %v", err)
}
arch := "x64"
if runtime.GOARCH != "amd64" {
@@ -101,6 +95,7 @@ func DownloadDependency() {
os.RemoveAll("./wintty")
os.RemoveAll("./wintty.zip")
}
return nil
}
func getExecutableFilePath() (string, error) {
+2 -1
View File
@@ -14,7 +14,8 @@ type Pty struct {
tty *conpty.ConPty
}
func DownloadDependency() {
func DownloadDependency() error {
return nil
}
func getExecutableFilePath() (string, error) {