mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-10-05 15:27:08 +08:00
v0.0.75
修复终止命令在选项选择时不可用的问题 展示分享链接时同时展示http和https协议的链接
This commit is contained in:
247
goecs.go
247
goecs.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/oneclickvirt/CommonMediaTests/commediatests"
|
"github.com/oneclickvirt/CommonMediaTests/commediatests"
|
||||||
@@ -38,7 +39,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ecsVersion = "v0.0.74"
|
ecsVersion = "v0.0.75"
|
||||||
menuMode bool
|
menuMode bool
|
||||||
onlyChinaTest bool
|
onlyChinaTest bool
|
||||||
input, choice string
|
input, choice string
|
||||||
@@ -62,6 +63,68 @@ var (
|
|||||||
goecsFlag = flag.NewFlagSet("goecs", flag.ContinueOnError)
|
goecsFlag = flag.NewFlagSet("goecs", flag.ContinueOnError)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getMenuChoice(language string) string {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
sigChan := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
defer signal.Stop(sigChan)
|
||||||
|
|
||||||
|
inputChan := make(chan string, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-sigChan:
|
||||||
|
fmt.Println("\n程序在选择过程中被用户中断")
|
||||||
|
os.Exit(1)
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
go func() {
|
||||||
|
var input string
|
||||||
|
fmt.Print("请输入选项 / Please enter your choice: ")
|
||||||
|
fmt.Scanln(&input)
|
||||||
|
input = strings.TrimSpace(input)
|
||||||
|
input = strings.TrimRight(input, "\n")
|
||||||
|
select {
|
||||||
|
case inputChan <- input:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case input := <-inputChan:
|
||||||
|
re := regexp.MustCompile(`^\d+$`) // 正则表达式匹配纯数字
|
||||||
|
if re.MatchString(input) {
|
||||||
|
choice := input
|
||||||
|
switch choice {
|
||||||
|
case "1", "2", "3", "4", "5", "6", "7", "8", "9", "10":
|
||||||
|
return choice
|
||||||
|
default:
|
||||||
|
if language == "zh" {
|
||||||
|
fmt.Println("无效的选项")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Invalid choice")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if language == "zh" {
|
||||||
|
fmt.Println("输入错误,请输入一个纯数字")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Invalid input, please enter a number")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
goecsFlag.BoolVar(&help, "h", false, "Show help information")
|
goecsFlag.BoolVar(&help, "h", false, "Show help information")
|
||||||
goecsFlag.BoolVar(&showVersion, "v", false, "Display version information")
|
goecsFlag.BoolVar(&showVersion, "v", false, "Display version information")
|
||||||
@@ -95,8 +158,6 @@ func main() {
|
|||||||
goecsFlag.PrintDefaults()
|
goecsFlag.PrintDefaults()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sig := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
if showVersion {
|
if showVersion {
|
||||||
fmt.Println(ecsVersion)
|
fmt.Println(ecsVersion)
|
||||||
return
|
return
|
||||||
@@ -149,103 +210,90 @@ func main() {
|
|||||||
}
|
}
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
fmt.Print("请输入选项 / Please enter your choice: ")
|
choice := getMenuChoice(language)
|
||||||
fmt.Scanln(&input)
|
switch choice {
|
||||||
input = strings.TrimSpace(input)
|
case "1":
|
||||||
input = strings.TrimRight(input, "\n")
|
basicStatus = true
|
||||||
re := regexp.MustCompile(`^\d+$`) // 正则表达式匹配纯数字
|
cpuTestStatus = true
|
||||||
if re.MatchString(input) {
|
memoryTestStatus = true
|
||||||
choice = input
|
diskTestStatus = true
|
||||||
switch choice {
|
commTestStatus = true
|
||||||
case "1":
|
utTestStatus = true
|
||||||
basicStatus = true
|
securityTestStatus = true
|
||||||
cpuTestStatus = true
|
emailTestStatus = true
|
||||||
memoryTestStatus = true
|
backtraceStatus = true
|
||||||
diskTestStatus = true
|
nt3Status = true
|
||||||
commTestStatus = true
|
speedTestStatus = true
|
||||||
utTestStatus = true
|
onlyChinaTest = utils.CheckChina(enableLogger)
|
||||||
securityTestStatus = true
|
break Loop
|
||||||
emailTestStatus = true
|
case "2":
|
||||||
backtraceStatus = true
|
basicStatus = true
|
||||||
nt3Status = true
|
cpuTestStatus = true
|
||||||
speedTestStatus = true
|
memoryTestStatus = true
|
||||||
onlyChinaTest = utils.CheckChina(enableLogger)
|
diskTestStatus = true
|
||||||
break Loop
|
speedTestStatus = true
|
||||||
case "2":
|
break Loop
|
||||||
basicStatus = true
|
case "3":
|
||||||
cpuTestStatus = true
|
basicStatus = true
|
||||||
memoryTestStatus = true
|
cpuTestStatus = true
|
||||||
diskTestStatus = true
|
memoryTestStatus = true
|
||||||
speedTestStatus = true
|
diskTestStatus = true
|
||||||
break Loop
|
utTestStatus = true
|
||||||
case "3":
|
nt3Status = true
|
||||||
basicStatus = true
|
speedTestStatus = true
|
||||||
cpuTestStatus = true
|
break Loop
|
||||||
memoryTestStatus = true
|
case "4":
|
||||||
diskTestStatus = true
|
basicStatus = true
|
||||||
utTestStatus = true
|
cpuTestStatus = true
|
||||||
nt3Status = true
|
memoryTestStatus = true
|
||||||
speedTestStatus = true
|
diskTestStatus = true
|
||||||
break Loop
|
backtraceStatus = true
|
||||||
case "4":
|
nt3Status = true
|
||||||
basicStatus = true
|
speedTestStatus = true
|
||||||
cpuTestStatus = true
|
break Loop
|
||||||
memoryTestStatus = true
|
case "5":
|
||||||
diskTestStatus = true
|
basicStatus = true
|
||||||
backtraceStatus = true
|
cpuTestStatus = true
|
||||||
nt3Status = true
|
memoryTestStatus = true
|
||||||
speedTestStatus = true
|
diskTestStatus = true
|
||||||
break Loop
|
commTestStatus = true
|
||||||
case "5":
|
utTestStatus = true
|
||||||
basicStatus = true
|
speedTestStatus = true
|
||||||
cpuTestStatus = true
|
break Loop
|
||||||
memoryTestStatus = true
|
case "6":
|
||||||
diskTestStatus = true
|
securityTestStatus = true
|
||||||
commTestStatus = true
|
speedTestStatus = true
|
||||||
utTestStatus = true
|
backtraceStatus = true
|
||||||
speedTestStatus = true
|
nt3Status = true
|
||||||
break Loop
|
break Loop
|
||||||
case "6":
|
case "7":
|
||||||
securityTestStatus = true
|
commTestStatus = true
|
||||||
speedTestStatus = true
|
utTestStatus = true
|
||||||
backtraceStatus = true
|
enabelUpload = false
|
||||||
nt3Status = true
|
break Loop
|
||||||
break Loop
|
case "8":
|
||||||
case "7":
|
basicStatus = true
|
||||||
commTestStatus = true
|
cpuTestStatus = true
|
||||||
utTestStatus = true
|
memoryTestStatus = true
|
||||||
enabelUpload = false
|
diskTestStatus = true
|
||||||
break Loop
|
securityTestStatus = false
|
||||||
case "8":
|
autoChangeDiskTestMethod = false
|
||||||
basicStatus = true
|
break Loop
|
||||||
cpuTestStatus = true
|
case "9":
|
||||||
memoryTestStatus = true
|
securityTestStatus = true
|
||||||
diskTestStatus = true
|
emailTestStatus = true
|
||||||
securityTestStatus = false
|
break Loop
|
||||||
autoChangeDiskTestMethod = false
|
case "10":
|
||||||
break Loop
|
backtraceStatus = true
|
||||||
case "9":
|
nt3Status = true
|
||||||
securityTestStatus = true
|
pingTestStatus = true
|
||||||
emailTestStatus = true
|
enabelUpload = false
|
||||||
break Loop
|
break Loop
|
||||||
case "10":
|
default:
|
||||||
backtraceStatus = true
|
|
||||||
nt3Status = true
|
|
||||||
pingTestStatus = true
|
|
||||||
enabelUpload = false
|
|
||||||
break Loop
|
|
||||||
default:
|
|
||||||
if language == "zh" {
|
|
||||||
fmt.Println("无效的选项")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Invalid choice")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if language == "zh" {
|
if language == "zh" {
|
||||||
fmt.Println("输入错误,请输入一个纯数字")
|
fmt.Println("无效的选项")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Invalid input, please enter a number")
|
fmt.Println("Invalid choice")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,6 +311,9 @@ func main() {
|
|||||||
basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string
|
basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string
|
||||||
output, tempOutput string
|
output, tempOutput string
|
||||||
)
|
)
|
||||||
|
// 设置主程序的信号处理
|
||||||
|
sig := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
// 启动一个goroutine来等待信号,内置计时器
|
// 启动一个goroutine来等待信号,内置计时器
|
||||||
go func() {
|
go func() {
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
|
@@ -238,7 +238,7 @@ func PrintAndCapture(f func(), tempOutput, output string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadText 上传文本内容到指定URL
|
// UploadText 上传文本内容到指定URL
|
||||||
func UploadText(absPath string) (string, error) {
|
func UploadText(absPath string) (string, string, error) {
|
||||||
primaryURL := "http://hpaste.spiritlhl.net/api/upload"
|
primaryURL := "http://hpaste.spiritlhl.net/api/upload"
|
||||||
backupURL := "https://paste.spiritlhl.net/api/upload"
|
backupURL := "https://paste.spiritlhl.net/api/upload"
|
||||||
token := network.SecurityUploadToken
|
token := network.SecurityUploadToken
|
||||||
@@ -250,10 +250,10 @@ func UploadText(absPath string) (string, error) {
|
|||||||
SetRetryFixedInterval(2 * time.Second)
|
SetRetryFixedInterval(2 * time.Second)
|
||||||
file, err := os.Open(absPath)
|
file, err := os.Open(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
upload := func(url string) (string, error) {
|
upload := func(url string) (string, string, error) {
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
SetHeader("Authorization", token).
|
SetHeader("Authorization", token).
|
||||||
SetHeader("Format", "RANDOM").
|
SetHeader("Format", "RANDOM").
|
||||||
@@ -264,23 +264,24 @@ func UploadText(absPath string) (string, error) {
|
|||||||
SetFileReader("file", "goecs.txt", file).
|
SetFileReader("file", "goecs.txt", file).
|
||||||
Post(url)
|
Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
|
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
|
||||||
return strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/"), nil
|
return strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/"),
|
||||||
|
strings.ReplaceAll(resp.String(), "http://hpaste.spiritlhl.net/", "https://paste.spiritlhl.net/"), nil
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("upload failed with status code: %d", resp.StatusCode)
|
return "", "", fmt.Errorf("upload failed with status code: %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, err := upload(primaryURL)
|
http_url, https_url, err := upload(primaryURL)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return result, nil
|
return http_url, https_url, nil
|
||||||
}
|
}
|
||||||
result, err = upload(backupURL)
|
http_url, https_url, err = upload(backupURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
return result, nil
|
return http_url, https_url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessAndUpload 创建结果文件并上传文件
|
// ProcessAndUpload 创建结果文件并上传文件
|
||||||
@@ -321,12 +322,12 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 上传文件并生成短链接
|
// 上传文件并生成短链接
|
||||||
shorturl, err3 := UploadText(absPath)
|
http_url, https_url, err3 := UploadText(absPath)
|
||||||
if err3 != nil {
|
if err3 != nil {
|
||||||
fmt.Println("Upload failed, cannot generate short URL.")
|
fmt.Println("Upload failed, cannot generate short URL.")
|
||||||
fmt.Println(err3.Error())
|
fmt.Println(err3.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Upload successful, short URL:", shorturl)
|
fmt.Println("Upload successful, short URL:", http_url, https_url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user