perf: hide window on windows when run external command for decode
This commit is contained in:
parent
2405a79ace
commit
30835ac469
|
@ -122,12 +122,14 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
|
|||
}
|
||||
|
||||
option := &redis.Options{
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
DialTimeout: time.Duration(config.ConnTimeout) * time.Second,
|
||||
ReadTimeout: time.Duration(config.ExecTimeout) * time.Second,
|
||||
WriteTimeout: time.Duration(config.ExecTimeout) * time.Second,
|
||||
TLSConfig: tlsConfig,
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
DialTimeout: time.Duration(config.ConnTimeout) * time.Second,
|
||||
ReadTimeout: time.Duration(config.ExecTimeout) * time.Second,
|
||||
WriteTimeout: time.Duration(config.ExecTimeout) * time.Second,
|
||||
TLSConfig: tlsConfig,
|
||||
DisableIndentity: true,
|
||||
IdentitySuffix: "tinyrdm_",
|
||||
}
|
||||
if config.Network == "unix" {
|
||||
option.Network = "unix"
|
||||
|
@ -138,10 +140,14 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
|
|||
}
|
||||
} else {
|
||||
option.Network = "tcp"
|
||||
port := 6379
|
||||
if config.Port > 0 {
|
||||
port = config.Port
|
||||
}
|
||||
if len(config.Addr) <= 0 {
|
||||
option.Addr = fmt.Sprintf("127.0.0.1:%d", config.Port)
|
||||
option.Addr = fmt.Sprintf("127.0.0.1:%d", port)
|
||||
} else {
|
||||
option.Addr = fmt.Sprintf("%s:%d", config.Addr, config.Port)
|
||||
option.Addr = fmt.Sprintf("%s:%d", config.Addr, port)
|
||||
}
|
||||
}
|
||||
if sshClient != nil {
|
||||
|
|
|
@ -2,10 +2,6 @@ package convutil
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/vrischmann/userdir"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
sliceutil "tinyrdm/backend/utils/slice"
|
||||
)
|
||||
|
@ -39,8 +35,7 @@ func (c CmdConvert) Encode(str string) (string, bool) {
|
|||
if len(args) <= 0 || !containHolder {
|
||||
args = append(args, base64Content)
|
||||
}
|
||||
cmd := exec.Command(c.EncodePath, args...)
|
||||
output, err := cmd.Output()
|
||||
output, err := runCommand(c.EncodePath, args...)
|
||||
if err != nil || len(output) <= 0 || string(output) == "[RDM-ERROR]" {
|
||||
return str, false
|
||||
}
|
||||
|
@ -67,8 +62,7 @@ func (c CmdConvert) Decode(str string) (string, bool) {
|
|||
if len(args) <= 0 || !containHolder {
|
||||
args = append(args, base64Content)
|
||||
}
|
||||
cmd := exec.Command(c.DecodePath, args...)
|
||||
output, err := cmd.Output()
|
||||
output, err := runCommand(c.DecodePath, args...)
|
||||
if err != nil || len(output) <= 0 || string(output) == "[RDM-ERROR]" {
|
||||
return str, false
|
||||
}
|
||||
|
@ -80,13 +74,3 @@ func (c CmdConvert) Decode(str string) (string, bool) {
|
|||
}
|
||||
return string(outputContent[:n]), true
|
||||
}
|
||||
|
||||
func (c CmdConvert) writeExecuteFile(content []byte, filename string) (string, error) {
|
||||
filepath := path.Join(userdir.GetConfigHome(), "TinyRDM", "decoder", filename)
|
||||
_ = os.Mkdir(path.Dir(filepath), 0777)
|
||||
err := os.WriteFile(filepath, content, 0777)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package convutil
|
||||
|
||||
import (
|
||||
"github.com/vrischmann/userdir"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func writeExecuteFile(content []byte, filename string) (string, error) {
|
||||
filepath := path.Join(userdir.GetConfigHome(), "TinyRDM", "decoder", filename)
|
||||
_ = os.Mkdir(path.Dir(filepath), 0777)
|
||||
err := os.WriteFile(filepath, content, 0777)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath, nil
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
//go:build !windows
|
||||
|
||||
package convutil
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func runCommand(name string, arg ...string) ([]byte, error) {
|
||||
cmd := exec.Command(name, arg...)
|
||||
return cmd.Output()
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
//go:build windows
|
||||
|
||||
package convutil
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func runCommand(name string, arg ...string) ([]byte, error) {
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||
return cmd.Output()
|
||||
}
|
|
@ -1,9 +1,5 @@
|
|||
package convutil
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type PhpConvert struct {
|
||||
CmdConvert
|
||||
}
|
||||
|
@ -51,12 +47,12 @@ func NewPhpConvert() *PhpConvert {
|
|||
}
|
||||
|
||||
var err error
|
||||
if err = exec.Command(c.DecodePath, "-v").Err; err != nil {
|
||||
if _, err = runCommand(c.DecodePath, "-v"); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var filepath string
|
||||
if filepath, err = c.writeExecuteFile([]byte(phpDecodeCode), "php_decoder.php"); err != nil {
|
||||
if filepath, err = writeExecuteFile([]byte(phpDecodeCode), "php_decoder.php"); err != nil {
|
||||
return nil
|
||||
}
|
||||
c.DecodeArgs = []string{filepath, "decode"}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package convutil
|
||||
|
||||
import "os/exec"
|
||||
|
||||
type PickleConvert struct {
|
||||
CmdConvert
|
||||
}
|
||||
|
@ -42,18 +40,18 @@ func NewPickleConvert() *PickleConvert {
|
|||
}
|
||||
c.DecodePath, c.EncodePath = "python3", "python3"
|
||||
var err error
|
||||
if err = exec.Command(c.DecodePath, "--version").Err; err != nil {
|
||||
if _, err = runCommand(c.DecodePath, "--version"); err != nil {
|
||||
c.DecodePath, c.EncodePath = "python", "python"
|
||||
if err = exec.Command(c.DecodePath, "--version").Err; err != nil {
|
||||
if _, err = runCommand(c.DecodePath, "--version"); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// check if pickle available
|
||||
if err = exec.Command(c.DecodePath, "-c", "import pickle").Err; err != nil {
|
||||
if _, err = runCommand(c.DecodePath, "-c", "import pickle"); err != nil {
|
||||
return nil
|
||||
}
|
||||
var filepath string
|
||||
if filepath, err = c.writeExecuteFile([]byte(pickleDecodeCode), "pickle_decoder.py"); err != nil {
|
||||
if filepath, err = writeExecuteFile([]byte(pickleDecodeCode), "pickle_decoder.py"); err != nil {
|
||||
return nil
|
||||
}
|
||||
c.DecodeArgs = []string{filepath, "decode"}
|
||||
|
|
|
@ -33,7 +33,7 @@ export const typesColor = {
|
|||
[types.SET]: '#F59E0B',
|
||||
[types.ZSET]: '#EF4444',
|
||||
[types.STREAM]: '#EC4899',
|
||||
[types.JSON]: '#374254',
|
||||
[types.JSON]: '#828766',
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ export const typesBgColor = {
|
|||
[types.SET]: '#FDF1DF',
|
||||
[types.ZSET]: '#FAEAED',
|
||||
[types.STREAM]: '#FDE6F1',
|
||||
[types.JSON]: '#C1C1D3',
|
||||
[types.JSON]: '#ECECD9',
|
||||
}
|
||||
|
||||
// export const typesName = Object.fromEntries(Object.entries(types).map(([key, value]) => [key, value.name]))
|
||||
|
|
Loading…
Reference in New Issue