Compare commits
No commits in common. "4a0807e4636ec78e6beab185bf0a63aa535662cc" and "44f8581a41b595b64b6cb3c5aec408079f55f43e" have entirely different histories.
4a0807e463
...
44f8581a41
|
@ -5,4 +5,3 @@ frontend/wailsjs
|
|||
design/
|
||||
.vscode
|
||||
.idea
|
||||
test
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
}
|
||||
|
||||
// startup is called when the app starts. The context is saved
|
||||
// so we can call the runtime methods
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
}
|
||||
|
||||
// Greet returns a greeting for the given name
|
||||
func (a *App) Greet(name string) string {
|
||||
return fmt.Sprintf("Hello %s, It's show time!", name)
|
||||
}
|
|
@ -2,19 +2,16 @@ package services
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
. "tinyrdm/backend/storage"
|
||||
"tinyrdm/backend/types"
|
||||
|
@ -40,7 +37,7 @@ type connectionService struct {
|
|||
}
|
||||
|
||||
type connectionItem struct {
|
||||
client redis.UniversalClient
|
||||
rdb *redis.Client
|
||||
ctx context.Context
|
||||
cancelFunc context.CancelFunc
|
||||
}
|
||||
|
@ -70,9 +67,9 @@ func (c *connectionService) Start(ctx context.Context) {
|
|||
|
||||
func (c *connectionService) Stop(ctx context.Context) {
|
||||
for _, item := range c.connMap {
|
||||
if item.client != nil {
|
||||
if item.rdb != nil {
|
||||
item.cancelFunc()
|
||||
item.client.Close()
|
||||
item.rdb.Close()
|
||||
}
|
||||
}
|
||||
c.connMap = map[string]connectionItem{}
|
||||
|
@ -116,48 +113,13 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
|
|||
}
|
||||
}
|
||||
|
||||
var tlsConfig *tls.Config
|
||||
if config.SSL.Enable {
|
||||
// setup tls config
|
||||
var certs []tls.Certificate
|
||||
if len(config.SSL.CertFile) > 0 && len(config.SSL.KeyFile) > 0 {
|
||||
if cert, err := tls.LoadX509KeyPair(config.SSL.CertFile, config.SSL.KeyFile); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
certs = []tls.Certificate{cert}
|
||||
}
|
||||
}
|
||||
|
||||
var caCertPool *x509.CertPool
|
||||
if len(config.SSL.CAFile) > 0 {
|
||||
ca, err := os.ReadFile(config.SSL.CAFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
caCertPool = x509.NewCertPool()
|
||||
caCertPool.AppendCertsFromPEM(ca)
|
||||
}
|
||||
|
||||
if len(certs) <= 0 {
|
||||
return nil, errors.New("tls config error")
|
||||
}
|
||||
|
||||
tlsConfig = &tls.Config{
|
||||
RootCAs: caCertPool,
|
||||
InsecureSkipVerify: false,
|
||||
Certificates: certs,
|
||||
}
|
||||
}
|
||||
|
||||
option := &redis.Options{
|
||||
ClientName: config.Name,
|
||||
Addr: fmt.Sprintf("%s:%d", config.Addr, config.Port),
|
||||
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,
|
||||
}
|
||||
if sshClient != nil {
|
||||
option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
|
@ -169,14 +131,13 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
|
|||
return option, nil
|
||||
}
|
||||
|
||||
func (c *connectionService) createRedisClient(config types.ConnectionConfig) (redis.UniversalClient, error) {
|
||||
func (c *connectionService) createRedisClient(config types.ConnectionConfig) (*redis.Client, error) {
|
||||
option, err := c.buildOption(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if config.Sentinel.Enable {
|
||||
// get master address via sentinel node
|
||||
sentinel := redis.NewSentinelClient(option)
|
||||
defer sentinel.Close()
|
||||
|
||||
|
@ -194,57 +155,6 @@ func (c *connectionService) createRedisClient(config types.ConnectionConfig) (re
|
|||
}
|
||||
|
||||
rdb := redis.NewClient(option)
|
||||
if config.Cluster.Enable {
|
||||
// connect to cluster
|
||||
var slots []redis.ClusterSlot
|
||||
if slots, err = rdb.ClusterSlots(c.ctx).Result(); err == nil {
|
||||
log.Println(slots)
|
||||
clusterOptions := &redis.ClusterOptions{
|
||||
//NewClient: nil,
|
||||
//MaxRedirects: 0,
|
||||
//RouteByLatency: false,
|
||||
//RouteRandomly: false,
|
||||
//ClusterSlots: nil,
|
||||
ClientName: option.ClientName,
|
||||
Dialer: option.Dialer,
|
||||
OnConnect: option.OnConnect,
|
||||
Protocol: option.Protocol,
|
||||
Username: option.Username,
|
||||
Password: option.Password,
|
||||
MaxRetries: option.MaxRetries,
|
||||
MinRetryBackoff: option.MinRetryBackoff,
|
||||
MaxRetryBackoff: option.MaxRetryBackoff,
|
||||
DialTimeout: option.DialTimeout,
|
||||
ContextTimeoutEnabled: option.ContextTimeoutEnabled,
|
||||
PoolFIFO: option.PoolFIFO,
|
||||
PoolSize: option.PoolSize,
|
||||
PoolTimeout: option.PoolTimeout,
|
||||
MinIdleConns: option.MinIdleConns,
|
||||
MaxIdleConns: option.MaxIdleConns,
|
||||
ConnMaxIdleTime: option.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: option.ConnMaxLifetime,
|
||||
TLSConfig: option.TLSConfig,
|
||||
DisableIndentity: option.DisableIndentity,
|
||||
}
|
||||
if option.Dialer != nil {
|
||||
clusterOptions.Dialer = option.Dialer
|
||||
clusterOptions.ReadTimeout = -2
|
||||
clusterOptions.WriteTimeout = -2
|
||||
}
|
||||
var addrs []string
|
||||
for _, slot := range slots {
|
||||
for _, node := range slot.Nodes {
|
||||
addrs = append(addrs, node.Addr)
|
||||
}
|
||||
}
|
||||
clusterOptions.Addrs = addrs
|
||||
clusterClient := redis.NewClusterClient(clusterOptions)
|
||||
return clusterClient, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return rdb, nil
|
||||
}
|
||||
|
||||
|
@ -283,14 +193,14 @@ func (c *connectionService) ListSentinelMasters(config types.ConnectionConfig) (
|
|||
}
|
||||
|
||||
func (c *connectionService) TestConnection(config types.ConnectionConfig) (resp types.JSResp) {
|
||||
client, err := c.createRedisClient(config)
|
||||
rdb, err := c.createRedisClient(config)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
defer rdb.Close()
|
||||
|
||||
if _, err = client.Ping(c.ctx).Result(); err != nil && err != redis.Nil {
|
||||
if _, err = rdb.Ping(c.ctx).Result(); err != nil && err != redis.Nil {
|
||||
resp.Msg = err.Error()
|
||||
} else {
|
||||
resp.Success = true
|
||||
|
@ -356,6 +266,23 @@ func (c *connectionService) SaveSortedConnection(sortedConns types.Connections)
|
|||
return
|
||||
}
|
||||
|
||||
// SelectKeyFile open file dialog to select a private key file
|
||||
func (c *connectionService) SelectKeyFile(title string) (resp types.JSResp) {
|
||||
filepath, err := runtime.OpenFileDialog(c.ctx, runtime.OpenDialogOptions{
|
||||
Title: title,
|
||||
ShowHiddenFiles: true,
|
||||
})
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
resp.Success = true
|
||||
resp.Data = map[string]any{
|
||||
"path": filepath,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CreateGroup create a new group
|
||||
func (c *connectionService) CreateGroup(name string) (resp types.JSResp) {
|
||||
err := c.conns.CreateGroup(name)
|
||||
|
@ -391,7 +318,7 @@ func (c *connectionService) DeleteGroup(name string, includeConn bool) (resp typ
|
|||
|
||||
// OpenConnection open redis server connection
|
||||
func (c *connectionService) OpenConnection(name string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(name, 0)
|
||||
rdb, ctx, err := c.getRedisClient(name, 0)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -403,51 +330,22 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) {
|
|||
var totaldb int
|
||||
if selConn.DBFilterType == "" || selConn.DBFilterType == "none" {
|
||||
// get total databases
|
||||
if config, err := client.ConfigGet(ctx, "databases").Result(); err == nil {
|
||||
if config, err := rdb.ConfigGet(ctx, "databases").Result(); err == nil {
|
||||
if total, err := strconv.Atoi(config["databases"]); err == nil {
|
||||
totaldb = total
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parse all db, response content like below
|
||||
var dbs []types.ConnectionDB
|
||||
var clusterKeyCount int64
|
||||
cluster, isCluster := client.(*redis.ClusterClient)
|
||||
if isCluster {
|
||||
var keyCount atomic.Int64
|
||||
err = cluster.ForEachMaster(ctx, func(ctx context.Context, cli *redis.Client) error {
|
||||
if size, serr := cli.DBSize(ctx).Result(); serr != nil {
|
||||
return serr
|
||||
} else {
|
||||
keyCount.Add(size)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
resp.Msg = "get db size error:" + err.Error()
|
||||
return
|
||||
}
|
||||
clusterKeyCount = keyCount.Load()
|
||||
|
||||
// only one database in cluster mode
|
||||
dbs = []types.ConnectionDB{
|
||||
{
|
||||
Name: "db0",
|
||||
Index: 0,
|
||||
Keys: int(clusterKeyCount),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
// get database info
|
||||
var res string
|
||||
res, err = client.Info(ctx, "keyspace").Result()
|
||||
res, err := rdb.Info(ctx, "keyspace").Result()
|
||||
if err != nil {
|
||||
resp.Msg = "get server info fail:" + err.Error()
|
||||
return
|
||||
}
|
||||
// parse all db, response content like below
|
||||
var dbs []types.ConnectionDB
|
||||
info := c.parseInfo(res)
|
||||
|
||||
if totaldb <= 0 {
|
||||
// cannot retrieve the database count by "CONFIG GET databases", try to get max index from keyspace
|
||||
keyspace := info["Keyspace"]
|
||||
|
@ -481,7 +379,6 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch selConn.DBFilterType {
|
||||
case "show":
|
||||
filterList := sliceutil.Unique(selConn.DBFilterList)
|
||||
|
@ -500,7 +397,6 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) {
|
|||
dbs = append(dbs, queryDB(idx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resp.Success = true
|
||||
resp.Data = map[string]any{
|
||||
|
@ -514,9 +410,9 @@ func (c *connectionService) CloseConnection(name string) (resp types.JSResp) {
|
|||
item, ok := c.connMap[name]
|
||||
if ok {
|
||||
delete(c.connMap, name)
|
||||
if item.client != nil {
|
||||
if item.rdb != nil {
|
||||
item.cancelFunc()
|
||||
item.client.Close()
|
||||
item.rdb.Close()
|
||||
}
|
||||
}
|
||||
resp.Success = true
|
||||
|
@ -525,19 +421,24 @@ func (c *connectionService) CloseConnection(name string) (resp types.JSResp) {
|
|||
|
||||
// get redis client from local cache or create a new open
|
||||
// if db >= 0, will also switch to db index
|
||||
func (c *connectionService) getRedisClient(connName string, db int) (redis.UniversalClient, context.Context, error) {
|
||||
func (c *connectionService) getRedisClient(connName string, db int) (*redis.Client, context.Context, error) {
|
||||
item, ok := c.connMap[connName]
|
||||
var client redis.UniversalClient
|
||||
var rdb *redis.Client
|
||||
var ctx context.Context
|
||||
if ok {
|
||||
client, ctx = item.client, item.ctx
|
||||
rdb, ctx = item.rdb, item.ctx
|
||||
} else {
|
||||
selConn := c.conns.GetConnection(connName)
|
||||
if selConn == nil {
|
||||
return nil, nil, fmt.Errorf("no match connection \"%s\"", connName)
|
||||
}
|
||||
|
||||
hook := redis2.NewHook(connName, func(cmd string, cost int64) {
|
||||
var err error
|
||||
rdb, err = c.createRedisClient(selConn.ConnectionConfig)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("create conenction error: %s", err.Error())
|
||||
}
|
||||
rdb.AddHook(redis2.NewHook(connName, func(cmd string, cost int64) {
|
||||
now := time.Now()
|
||||
//last := strings.LastIndex(cmd, ":")
|
||||
//if last != -1 {
|
||||
|
@ -549,48 +450,26 @@ func (c *connectionService) getRedisClient(connName string, db int) (redis.Unive
|
|||
Cmd: cmd,
|
||||
Cost: cost,
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
var err error
|
||||
client, err = c.createRedisClient(selConn.ConnectionConfig)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("create conenction error: %s", err.Error())
|
||||
}
|
||||
// add hook to each node in cluster mode
|
||||
var cluster *redis.ClusterClient
|
||||
if cluster, ok = client.(*redis.ClusterClient); ok {
|
||||
err = cluster.ForEachShard(c.ctx, func(ctx context.Context, cli *redis.Client) error {
|
||||
cli.AddHook(hook)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("get cluster nodes error: %s", err.Error())
|
||||
}
|
||||
} else {
|
||||
client.AddHook(hook)
|
||||
}
|
||||
|
||||
if _, err = client.Ping(c.ctx).Result(); err != nil && err != redis.Nil {
|
||||
if _, err = rdb.Ping(c.ctx).Result(); err != nil && err != redis.Nil {
|
||||
return nil, nil, errors.New("can not connect to redis server:" + err.Error())
|
||||
}
|
||||
var cancelFunc context.CancelFunc
|
||||
ctx, cancelFunc = context.WithCancel(c.ctx)
|
||||
c.connMap[connName] = connectionItem{
|
||||
client: client,
|
||||
rdb: rdb,
|
||||
ctx: ctx,
|
||||
cancelFunc: cancelFunc,
|
||||
}
|
||||
}
|
||||
|
||||
if db >= 0 {
|
||||
var rdb *redis.Client
|
||||
if rdb, ok = client.(*redis.Client); ok && rdb != nil {
|
||||
if err := rdb.Do(ctx, "select", strconv.Itoa(db)).Err(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return client, ctx, nil
|
||||
return rdb, ctx, nil
|
||||
}
|
||||
|
||||
// parse command response content which use "redis info"
|
||||
|
@ -632,14 +511,14 @@ func (c *connectionService) parseDBItemInfo(info string) map[string]int {
|
|||
|
||||
// ServerInfo get server info
|
||||
func (c *connectionService) ServerInfo(name string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(name, 0)
|
||||
rdb, ctx, err := c.getRedisClient(name, 0)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
// get database info
|
||||
res, err := client.Info(ctx).Result()
|
||||
res, err := rdb.Info(ctx).Result()
|
||||
if err != nil {
|
||||
resp.Msg = "get server info fail:" + err.Error()
|
||||
return
|
||||
|
@ -658,48 +537,41 @@ func (c *connectionService) OpenDatabase(connName string, db int, match string,
|
|||
|
||||
// ScanKeys scan all keys
|
||||
func (c *connectionService) ScanKeys(connName string, db int, match, keyType string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
filterType := len(keyType) > 0
|
||||
var countPerScan int64 = 10000
|
||||
// define sub scan function
|
||||
scan := func(ctx context.Context, cli redis.UniversalClient, appendFunc func(k any)) error {
|
||||
var iter *redis.ScanIterator
|
||||
if filterType {
|
||||
iter = cli.ScanType(ctx, 0, match, countPerScan, keyType).Iterator()
|
||||
} else {
|
||||
iter = cli.Scan(ctx, 0, match, countPerScan).Iterator()
|
||||
}
|
||||
for iter.Next(ctx) {
|
||||
appendFunc(strutil.EncodeRedisKey(iter.Val()))
|
||||
}
|
||||
return iter.Err()
|
||||
}
|
||||
|
||||
var keys []any
|
||||
if cluster, ok := client.(*redis.ClusterClient); ok {
|
||||
// cluster mode
|
||||
var mutex sync.Mutex
|
||||
err = cluster.ForEachMaster(ctx, func(ctx context.Context, cli *redis.Client) error {
|
||||
return scan(ctx, cli, func(k any) {
|
||||
mutex.Lock()
|
||||
keys = append(keys, k)
|
||||
mutex.Unlock()
|
||||
})
|
||||
})
|
||||
//keys := map[string]keyItem{}
|
||||
var cursor uint64
|
||||
for {
|
||||
var loadedKey []string
|
||||
if filterType {
|
||||
loadedKey, cursor, err = rdb.ScanType(ctx, cursor, match, 10000, keyType).Result()
|
||||
} else {
|
||||
err = scan(ctx, client, func(k any) {
|
||||
keys = append(keys, k)
|
||||
})
|
||||
loadedKey, cursor, err = rdb.Scan(ctx, cursor, match, 10000).Result()
|
||||
}
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
for _, k := range loadedKey {
|
||||
keys = append(keys, strutil.EncodeRedisKey(k))
|
||||
}
|
||||
//for _, k := range loadedKey {
|
||||
// //t, _ := rdb.Type(ctx, k).Result()
|
||||
// keys[k] = keyItem{Type: "t"}
|
||||
//}
|
||||
//keys = append(keys, loadedKey...)
|
||||
// no more loadedKey
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
resp.Success = true
|
||||
resp.Data = map[string]any{
|
||||
|
@ -710,7 +582,7 @@ func (c *connectionService) ScanKeys(connName string, db int, match, keyType str
|
|||
|
||||
// GetKeyValue get value by key
|
||||
func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -719,7 +591,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
key := strutil.DecodeRedisKey(k)
|
||||
var keyType string
|
||||
var dur time.Duration
|
||||
keyType, err = client.Type(ctx, key).Result()
|
||||
keyType, err = rdb.Type(ctx, key).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -731,7 +603,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
}
|
||||
|
||||
var ttl int64
|
||||
if dur, err = client.TTL(ctx, key).Result(); err != nil {
|
||||
if dur, err = rdb.TTL(ctx, key).Result(); err != nil {
|
||||
ttl = -1
|
||||
} else {
|
||||
if dur < 0 {
|
||||
|
@ -747,18 +619,18 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
switch strings.ToLower(keyType) {
|
||||
case "string":
|
||||
var str string
|
||||
str, err = client.Get(ctx, key).Result()
|
||||
str, err = rdb.Get(ctx, key).Result()
|
||||
value, viewAs = strutil.ConvertTo(str, viewAs)
|
||||
size, _ = client.StrLen(ctx, key).Result()
|
||||
size, _ = rdb.StrLen(ctx, key).Result()
|
||||
case "list":
|
||||
value, err = client.LRange(ctx, key, 0, -1).Result()
|
||||
size, _ = client.LLen(ctx, key).Result()
|
||||
value, err = rdb.LRange(ctx, key, 0, -1).Result()
|
||||
size, _ = rdb.LLen(ctx, key).Result()
|
||||
case "hash":
|
||||
//value, err = client.HGetAll(ctx, key).Result()
|
||||
//value, err = rdb.HGetAll(ctx, key).Result()
|
||||
items := map[string]string{}
|
||||
for {
|
||||
var loadedVal []string
|
||||
loadedVal, cursor, err = client.HScan(ctx, key, cursor, "*", 10000).Result()
|
||||
loadedVal, cursor, err = rdb.HScan(ctx, key, cursor, "*", 10000).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -771,13 +643,13 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
}
|
||||
}
|
||||
value = items
|
||||
size, _ = client.HLen(ctx, key).Result()
|
||||
size, _ = rdb.HLen(ctx, key).Result()
|
||||
case "set":
|
||||
//value, err = client.SMembers(ctx, key).Result()
|
||||
//value, err = rdb.SMembers(ctx, key).Result()
|
||||
items := []string{}
|
||||
for {
|
||||
var loadedKey []string
|
||||
loadedKey, cursor, err = client.SScan(ctx, key, cursor, "*", 10000).Result()
|
||||
loadedKey, cursor, err = rdb.SScan(ctx, key, cursor, "*", 10000).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -788,13 +660,13 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
}
|
||||
}
|
||||
value = items
|
||||
size, _ = client.SCard(ctx, key).Result()
|
||||
size, _ = rdb.SCard(ctx, key).Result()
|
||||
case "zset":
|
||||
//value, err = client.ZRangeWithScores(ctx, key, 0, -1).Result()
|
||||
//value, err = rdb.ZRangeWithScores(ctx, key, 0, -1).Result()
|
||||
var items []types.ZSetItem
|
||||
for {
|
||||
var loadedVal []string
|
||||
loadedVal, cursor, err = client.ZScan(ctx, key, cursor, "*", 10000).Result()
|
||||
loadedVal, cursor, err = rdb.ZScan(ctx, key, cursor, "*", 10000).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -813,11 +685,11 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
}
|
||||
}
|
||||
value = items
|
||||
size, _ = client.ZCard(ctx, key).Result()
|
||||
size, _ = rdb.ZCard(ctx, key).Result()
|
||||
case "stream":
|
||||
var msgs []redis.XMessage
|
||||
items := []types.StreamItem{}
|
||||
msgs, err = client.XRevRange(ctx, key, "+", "-").Result()
|
||||
msgs, err = rdb.XRevRange(ctx, key, "+", "-").Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -829,7 +701,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
})
|
||||
}
|
||||
value = items
|
||||
size, _ = client.XLen(ctx, key).Result()
|
||||
size, _ = rdb.XLen(ctx, key).Result()
|
||||
}
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
|
@ -849,7 +721,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, k any, viewAs s
|
|||
// SetKeyValue set value by key
|
||||
// @param ttl <= 0 means keep current ttl
|
||||
func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType string, value any, ttl int64, viewAs string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -858,7 +730,7 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
key := strutil.DecodeRedisKey(k)
|
||||
var expiration time.Duration
|
||||
if ttl < 0 {
|
||||
if expiration, err = client.PTTL(ctx, key).Result(); err != nil {
|
||||
if expiration, err = rdb.PTTL(ctx, key).Result(); err != nil {
|
||||
expiration = redis.KeepTTL
|
||||
}
|
||||
} else {
|
||||
|
@ -875,10 +747,10 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
resp.Msg = fmt.Sprintf(`save to "%s" type fail: %s`, viewAs, err.Error())
|
||||
return
|
||||
}
|
||||
_, err = client.Set(ctx, key, saveStr, 0).Result()
|
||||
_, err = rdb.Set(ctx, key, saveStr, 0).Result()
|
||||
// set expiration lonely, not "keepttl"
|
||||
if err == nil && expiration > 0 {
|
||||
client.Expire(ctx, key, expiration)
|
||||
rdb.Expire(ctx, key, expiration)
|
||||
}
|
||||
}
|
||||
case "list":
|
||||
|
@ -886,9 +758,9 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
resp.Msg = "invalid list value"
|
||||
return
|
||||
} else {
|
||||
err = client.LPush(ctx, key, strs...).Err()
|
||||
err = rdb.LPush(ctx, key, strs...).Err()
|
||||
if err == nil && expiration > 0 {
|
||||
client.Expire(ctx, key, expiration)
|
||||
rdb.Expire(ctx, key, expiration)
|
||||
}
|
||||
}
|
||||
case "hash":
|
||||
|
@ -898,7 +770,7 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
} else {
|
||||
total := len(strs)
|
||||
if total > 1 {
|
||||
_, err = client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||
_, err = rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||
for i := 0; i < total; i += 2 {
|
||||
pipe.HSet(ctx, key, strs[i], strs[i+1])
|
||||
}
|
||||
|
@ -915,9 +787,9 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
return
|
||||
} else {
|
||||
if len(strs) > 0 {
|
||||
err = client.SAdd(ctx, key, strs...).Err()
|
||||
err = rdb.SAdd(ctx, key, strs...).Err()
|
||||
if err == nil && expiration > 0 {
|
||||
client.Expire(ctx, key, expiration)
|
||||
rdb.Expire(ctx, key, expiration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -935,9 +807,9 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
Member: strs[i],
|
||||
})
|
||||
}
|
||||
err = client.ZAdd(ctx, key, members...).Err()
|
||||
err = rdb.ZAdd(ctx, key, members...).Err()
|
||||
if err == nil && expiration > 0 {
|
||||
client.Expire(ctx, key, expiration)
|
||||
rdb.Expire(ctx, key, expiration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -947,13 +819,13 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
return
|
||||
} else {
|
||||
if len(strs) > 2 {
|
||||
err = client.XAdd(ctx, &redis.XAddArgs{
|
||||
err = rdb.XAdd(ctx, &redis.XAddArgs{
|
||||
Stream: key,
|
||||
ID: strs[0].(string),
|
||||
Values: strs[1:],
|
||||
}).Err()
|
||||
if err == nil && expiration > 0 {
|
||||
client.Expire(ctx, key, expiration)
|
||||
rdb.Expire(ctx, key, expiration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -972,7 +844,7 @@ func (c *connectionService) SetKeyValue(connName string, db int, k any, keyType
|
|||
|
||||
// SetHashValue set hash field
|
||||
func (c *connectionService) SetHashValue(connName string, db int, k any, field, newField, value string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -983,23 +855,23 @@ func (c *connectionService) SetHashValue(connName string, db int, k any, field,
|
|||
updatedField := map[string]string{}
|
||||
if len(field) <= 0 {
|
||||
// old filed is empty, add new field
|
||||
_, err = client.HSet(ctx, key, newField, value).Result()
|
||||
_, err = rdb.HSet(ctx, key, newField, value).Result()
|
||||
updatedField[newField] = value
|
||||
} else if len(newField) <= 0 {
|
||||
// new field is empty, delete old field
|
||||
_, err = client.HDel(ctx, key, field, value).Result()
|
||||
_, err = rdb.HDel(ctx, key, field, value).Result()
|
||||
removedField = append(removedField, field)
|
||||
} else if field == newField {
|
||||
// replace field
|
||||
_, err = client.HSet(ctx, key, newField, value).Result()
|
||||
_, err = rdb.HSet(ctx, key, newField, value).Result()
|
||||
updatedField[newField] = value
|
||||
} else {
|
||||
// remove old field and add new field
|
||||
if _, err = client.HDel(ctx, key, field).Result(); err != nil {
|
||||
if _, err = rdb.HDel(ctx, key, field).Result(); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
_, err = client.HSet(ctx, key, newField, value).Result()
|
||||
_, err = rdb.HSet(ctx, key, newField, value).Result()
|
||||
removedField = append(removedField, field)
|
||||
updatedField[newField] = value
|
||||
}
|
||||
|
@ -1018,7 +890,7 @@ func (c *connectionService) SetHashValue(connName string, db int, k any, field,
|
|||
|
||||
// AddHashField add or update hash field
|
||||
func (c *connectionService) AddHashField(connName string, db int, k any, action int, fieldItems []any) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1030,7 +902,7 @@ func (c *connectionService) AddHashField(connName string, db int, k any, action
|
|||
case 1:
|
||||
// ignore duplicated fields
|
||||
for i := 0; i < len(fieldItems); i += 2 {
|
||||
_, err = client.HSetNX(ctx, key, fieldItems[i].(string), fieldItems[i+1]).Result()
|
||||
_, err = rdb.HSetNX(ctx, key, fieldItems[i].(string), fieldItems[i+1]).Result()
|
||||
if err == nil {
|
||||
updated[fieldItems[i].(string)] = fieldItems[i+1]
|
||||
}
|
||||
|
@ -1039,9 +911,9 @@ func (c *connectionService) AddHashField(connName string, db int, k any, action
|
|||
// overwrite duplicated fields
|
||||
total := len(fieldItems)
|
||||
if total > 1 {
|
||||
_, err = client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||
_, err = rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||
for i := 0; i < total; i += 2 {
|
||||
client.HSet(ctx, key, fieldItems[i], fieldItems[i+1])
|
||||
rdb.HSet(ctx, key, fieldItems[i], fieldItems[i+1])
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@ -1064,7 +936,7 @@ func (c *connectionService) AddHashField(connName string, db int, k any, action
|
|||
|
||||
// AddListItem add item to list or remove from it
|
||||
func (c *connectionService) AddListItem(connName string, db int, k any, action int, items []any) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1075,11 +947,11 @@ func (c *connectionService) AddListItem(connName string, db int, k any, action i
|
|||
switch action {
|
||||
case 0:
|
||||
// push to head
|
||||
_, err = client.LPush(ctx, key, items...).Result()
|
||||
_, err = rdb.LPush(ctx, key, items...).Result()
|
||||
leftPush = append(leftPush, items...)
|
||||
default:
|
||||
// append to tail
|
||||
_, err = client.RPush(ctx, key, items...).Result()
|
||||
_, err = rdb.RPush(ctx, key, items...).Result()
|
||||
rightPush = append(rightPush, items...)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -1097,7 +969,7 @@ func (c *connectionService) AddListItem(connName string, db int, k any, action i
|
|||
|
||||
// SetListItem update or remove list item by index
|
||||
func (c *connectionService) SetListItem(connName string, db int, k any, index int64, value string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1108,13 +980,13 @@ func (c *connectionService) SetListItem(connName string, db int, k any, index in
|
|||
updated := map[int64]string{}
|
||||
if len(value) <= 0 {
|
||||
// remove from list
|
||||
err = client.LSet(ctx, key, index, "---VALUE_REMOVED_BY_TINY_RDM---").Err()
|
||||
err = rdb.LSet(ctx, key, index, "---VALUE_REMOVED_BY_TINY_RDM---").Err()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
err = client.LRem(ctx, key, 1, "---VALUE_REMOVED_BY_TINY_RDM---").Err()
|
||||
err = rdb.LRem(ctx, key, 1, "---VALUE_REMOVED_BY_TINY_RDM---").Err()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1122,7 +994,7 @@ func (c *connectionService) SetListItem(connName string, db int, k any, index in
|
|||
removed = append(removed, index)
|
||||
} else {
|
||||
// replace index value
|
||||
err = client.LSet(ctx, key, index, value).Err()
|
||||
err = rdb.LSet(ctx, key, index, value).Err()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1140,7 +1012,7 @@ func (c *connectionService) SetListItem(connName string, db int, k any, index in
|
|||
|
||||
// SetSetItem add members to set or remove from set
|
||||
func (c *connectionService) SetSetItem(connName string, db int, k any, remove bool, members []any) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1148,9 +1020,9 @@ func (c *connectionService) SetSetItem(connName string, db int, k any, remove bo
|
|||
|
||||
key := strutil.DecodeRedisKey(k)
|
||||
if remove {
|
||||
_, err = client.SRem(ctx, key, members...).Result()
|
||||
_, err = rdb.SRem(ctx, key, members...).Result()
|
||||
} else {
|
||||
_, err = client.SAdd(ctx, key, members...).Result()
|
||||
_, err = rdb.SAdd(ctx, key, members...).Result()
|
||||
}
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
|
@ -1163,15 +1035,15 @@ func (c *connectionService) SetSetItem(connName string, db int, k any, remove bo
|
|||
|
||||
// UpdateSetItem replace member of set
|
||||
func (c *connectionService) UpdateSetItem(connName string, db int, k any, value, newValue string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
key := strutil.DecodeRedisKey(k)
|
||||
_, _ = client.SRem(ctx, key, value).Result()
|
||||
_, err = client.SAdd(ctx, key, newValue).Result()
|
||||
_, _ = rdb.SRem(ctx, key, value).Result()
|
||||
_, err = rdb.SAdd(ctx, key, newValue).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1183,7 +1055,7 @@ func (c *connectionService) UpdateSetItem(connName string, db int, k any, value,
|
|||
|
||||
// UpdateZSetValue update value of sorted set member
|
||||
func (c *connectionService) UpdateZSetValue(connName string, db int, k any, value, newValue string, score float64) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1194,24 +1066,24 @@ func (c *connectionService) UpdateZSetValue(connName string, db int, k any, valu
|
|||
var removed []string
|
||||
if len(newValue) <= 0 {
|
||||
// blank new value, delete value
|
||||
_, err = client.ZRem(ctx, key, value).Result()
|
||||
_, err = rdb.ZRem(ctx, key, value).Result()
|
||||
if err == nil {
|
||||
removed = append(removed, value)
|
||||
}
|
||||
} else if newValue == value {
|
||||
// update score only
|
||||
_, err = client.ZAdd(ctx, key, redis.Z{
|
||||
_, err = rdb.ZAdd(ctx, key, redis.Z{
|
||||
Score: score,
|
||||
Member: value,
|
||||
}).Result()
|
||||
} else {
|
||||
// remove old value and add new one
|
||||
_, err = client.ZRem(ctx, key, value).Result()
|
||||
_, err = rdb.ZRem(ctx, key, value).Result()
|
||||
if err == nil {
|
||||
removed = append(removed, value)
|
||||
}
|
||||
|
||||
_, err = client.ZAdd(ctx, key, redis.Z{
|
||||
_, err = rdb.ZAdd(ctx, key, redis.Z{
|
||||
Score: score,
|
||||
Member: newValue,
|
||||
}).Result()
|
||||
|
@ -1234,7 +1106,7 @@ func (c *connectionService) UpdateZSetValue(connName string, db int, k any, valu
|
|||
|
||||
// AddZSetValue add item to sorted set
|
||||
func (c *connectionService) AddZSetValue(connName string, db int, k any, action int, valueScore map[string]float64) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1251,10 +1123,10 @@ func (c *connectionService) AddZSetValue(connName string, db int, k any, action
|
|||
switch action {
|
||||
case 1:
|
||||
// ignore duplicated fields
|
||||
_, err = client.ZAddNX(ctx, key, members...).Result()
|
||||
_, err = rdb.ZAddNX(ctx, key, members...).Result()
|
||||
default:
|
||||
// overwrite duplicated fields
|
||||
_, err = client.ZAdd(ctx, key, members...).Result()
|
||||
_, err = rdb.ZAdd(ctx, key, members...).Result()
|
||||
}
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
|
@ -1267,14 +1139,14 @@ func (c *connectionService) AddZSetValue(connName string, db int, k any, action
|
|||
|
||||
// AddStreamValue add stream field
|
||||
func (c *connectionService) AddStreamValue(connName string, db int, k any, ID string, fieldItems []any) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
key := strutil.DecodeRedisKey(k)
|
||||
_, err = client.XAdd(ctx, &redis.XAddArgs{
|
||||
_, err = rdb.XAdd(ctx, &redis.XAddArgs{
|
||||
Stream: key,
|
||||
ID: ID,
|
||||
Values: fieldItems,
|
||||
|
@ -1290,21 +1162,21 @@ func (c *connectionService) AddStreamValue(connName string, db int, k any, ID st
|
|||
|
||||
// RemoveStreamValues remove stream values by id
|
||||
func (c *connectionService) RemoveStreamValues(connName string, db int, k any, IDs []string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
key := strutil.DecodeRedisKey(k)
|
||||
_, err = client.XDel(ctx, key, IDs...).Result()
|
||||
_, err = rdb.XDel(ctx, key, IDs...).Result()
|
||||
resp.Success = true
|
||||
return
|
||||
}
|
||||
|
||||
// SetKeyTTL set ttl of key
|
||||
func (c *connectionService) SetKeyTTL(connName string, db int, k any, ttl int64) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1313,13 +1185,13 @@ func (c *connectionService) SetKeyTTL(connName string, db int, k any, ttl int64)
|
|||
key := strutil.DecodeRedisKey(k)
|
||||
var expiration time.Duration
|
||||
if ttl < 0 {
|
||||
if err = client.Persist(ctx, key).Err(); err != nil {
|
||||
if err = rdb.Persist(ctx, key).Err(); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
expiration = time.Duration(ttl) * time.Second
|
||||
if err = client.Expire(ctx, key, expiration).Err(); err != nil {
|
||||
if err = rdb.Expire(ctx, key, expiration).Err(); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
@ -1331,7 +1203,7 @@ func (c *connectionService) SetKeyTTL(connName string, db int, k any, ttl int64)
|
|||
|
||||
// DeleteKey remove redis key
|
||||
func (c *connectionService) DeleteKey(connName string, db int, k any) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1341,39 +1213,29 @@ func (c *connectionService) DeleteKey(connName string, db int, k any) (resp type
|
|||
var deletedKeys []string
|
||||
if strings.HasSuffix(key, "*") {
|
||||
// delete by prefix
|
||||
var mutex sync.Mutex
|
||||
del := func(ctx context.Context, cli redis.UniversalClient) error {
|
||||
iter := cli.Scan(ctx, 0, key, 10000).Iterator()
|
||||
for iter.Next(ctx) {
|
||||
subKey := iter.Val()
|
||||
if err = cli.Unlink(ctx, subKey).Err(); err != nil {
|
||||
log.Println("unlink error", err.Error())
|
||||
return err
|
||||
} else {
|
||||
mutex.Lock()
|
||||
deletedKeys = append(deletedKeys, subKey)
|
||||
mutex.Unlock()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if cluster, ok := client.(*redis.ClusterClient); ok {
|
||||
// cluster mode
|
||||
err = cluster.ForEachMaster(ctx, func(ctx context.Context, cli *redis.Client) error {
|
||||
return del(ctx, cli)
|
||||
})
|
||||
} else {
|
||||
err = del(ctx, client)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
var cursor uint64
|
||||
for {
|
||||
var loadedKey []string
|
||||
if loadedKey, cursor, err = rdb.Scan(ctx, cursor, key, 10000).Result(); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
} else {
|
||||
if err = rdb.Del(ctx, loadedKey...).Err(); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
} else {
|
||||
deletedKeys = append(deletedKeys, loadedKey...)
|
||||
}
|
||||
}
|
||||
|
||||
// no more loadedKey
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// delete key only
|
||||
_, err = client.Del(ctx, key).Result()
|
||||
_, err = rdb.Del(ctx, key).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
|
@ -1390,18 +1252,14 @@ func (c *connectionService) DeleteKey(connName string, db int, k any) (resp type
|
|||
|
||||
// RenameKey rename key
|
||||
func (c *connectionService) RenameKey(connName string, db int, key, newKey string) (resp types.JSResp) {
|
||||
client, ctx, err := c.getRedisClient(connName, db)
|
||||
rdb, ctx, err := c.getRedisClient(connName, db)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := client.(*redis.ClusterClient); ok {
|
||||
resp.Msg = "RENAME not support in cluster mode yet"
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = client.RenameNX(ctx, key, newKey).Result(); err != nil {
|
||||
_, err = rdb.RenameNX(ctx, key, newKey).Result()
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -113,13 +113,11 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) {
|
|||
}
|
||||
|
||||
func (p *preferencesService) SaveWindowSize(width, height int) {
|
||||
if width >= consts.DEFAULT_WINDOW_WIDTH && height >= consts.DEFAULT_WINDOW_HEIGHT {
|
||||
p.UpdatePreferences(map[string]any{
|
||||
"behavior.windowWidth": width,
|
||||
"behavior.windowHeight": height,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (p *preferencesService) GetWindowSize() (width, height int) {
|
||||
data := p.pref.GetPreferences()
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
"tinyrdm/backend/types"
|
||||
)
|
||||
|
||||
type systemService struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
var system *systemService
|
||||
var onceSystem sync.Once
|
||||
|
||||
func System() *systemService {
|
||||
if system == nil {
|
||||
onceSystem.Do(func() {
|
||||
system = &systemService{}
|
||||
go system.loopWindowEvent()
|
||||
})
|
||||
}
|
||||
return system
|
||||
}
|
||||
|
||||
func (s *systemService) Start(ctx context.Context) {
|
||||
s.ctx = ctx
|
||||
}
|
||||
|
||||
// SelectFile open file dialog to select a file
|
||||
func (s *systemService) SelectFile(title string) (resp types.JSResp) {
|
||||
filepath, err := runtime.OpenFileDialog(s.ctx, runtime.OpenDialogOptions{
|
||||
Title: title,
|
||||
ShowHiddenFiles: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
resp.Success = true
|
||||
resp.Data = map[string]any{
|
||||
"path": filepath,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *systemService) loopWindowEvent() {
|
||||
var fullscreen, maximised, minimised, normal bool
|
||||
var width, height int
|
||||
var dirty bool
|
||||
for {
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
if s.ctx == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
dirty = false
|
||||
if f := runtime.WindowIsFullscreen(s.ctx); f != fullscreen {
|
||||
// full-screen switched
|
||||
fullscreen = f
|
||||
dirty = true
|
||||
}
|
||||
|
||||
if w, h := runtime.WindowGetSize(s.ctx); w != width || h != height {
|
||||
// window size changed
|
||||
width, height = w, h
|
||||
dirty = true
|
||||
}
|
||||
|
||||
if m := runtime.WindowIsMaximised(s.ctx); m != maximised {
|
||||
maximised = m
|
||||
dirty = true
|
||||
}
|
||||
|
||||
if m := runtime.WindowIsMinimised(s.ctx); m != minimised {
|
||||
minimised = m
|
||||
dirty = true
|
||||
}
|
||||
|
||||
if n := runtime.WindowIsNormal(s.ctx); n != normal {
|
||||
normal = n
|
||||
dirty = true
|
||||
}
|
||||
|
||||
if dirty {
|
||||
runtime.EventsEmit(s.ctx, "window_changed", map[string]any{
|
||||
"fullscreen": fullscreen,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"maximised": maximised,
|
||||
"minimised": minimised,
|
||||
"normal": normal,
|
||||
})
|
||||
|
||||
if !fullscreen && !minimised {
|
||||
// save window size
|
||||
Preferences().SaveWindowSize(width, height)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,10 +16,8 @@ type ConnectionConfig struct {
|
|||
DBFilterType string `json:"dbFilterType" yaml:"db_filter_type,omitempty"`
|
||||
DBFilterList []int `json:"dbFilterList" yaml:"db_filter_list,omitempty"`
|
||||
MarkColor string `json:"markColor,omitempty" yaml:"mark_color,omitempty"`
|
||||
SSL ConnectionSSL `json:"ssl,omitempty" yaml:"ssl,omitempty"`
|
||||
SSH ConnectionSSH `json:"ssh,omitempty" yaml:"ssh,omitempty"`
|
||||
Sentinel ConnectionSentinel `json:"sentinel,omitempty" yaml:"sentinel,omitempty"`
|
||||
Cluster ConnectionCluster `json:"cluster,omitempty" yaml:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
|
@ -30,6 +28,11 @@ type Connection struct {
|
|||
|
||||
type Connections []Connection
|
||||
|
||||
type ConnectionGroup struct {
|
||||
GroupName string `json:"groupName" yaml:"group_name"`
|
||||
Connections []Connection `json:"connections" yaml:"connections"`
|
||||
}
|
||||
|
||||
type ConnectionDB struct {
|
||||
Name string `json:"name"`
|
||||
Index int `json:"index"`
|
||||
|
@ -38,31 +41,20 @@ type ConnectionDB struct {
|
|||
AvgTTL int `json:"avgTtl,omitempty"`
|
||||
}
|
||||
|
||||
type ConnectionSSL struct {
|
||||
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`
|
||||
KeyFile string `json:"keyFile,omitempty" yaml:"keyFile,omitempty"`
|
||||
CertFile string `json:"certFile,omitempty" yaml:"certFile,omitempty"`
|
||||
CAFile string `json:"caFile,omitempty" yaml:"caFile,omitempty"`
|
||||
}
|
||||
|
||||
type ConnectionSSH struct {
|
||||
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`
|
||||
Enable bool `json:"enable" yaml:"enable"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"`
|
||||
LoginType string `json:"loginType,omitempty" yaml:"login_type"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
LoginType string `json:"loginType" yaml:"login_type"`
|
||||
Username string `json:"username" yaml:"username,omitempty"`
|
||||
Password string `json:"password,omitempty" yaml:"password,omitempty"`
|
||||
PKFile string `json:"pkFile,omitempty" yaml:"pk_file,omitempty"`
|
||||
Passphrase string `json:"passphrase,omitempty" yaml:"passphrase,omitempty"`
|
||||
}
|
||||
|
||||
type ConnectionSentinel struct {
|
||||
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`
|
||||
Master string `json:"master,omitempty" yaml:"master,omitempty"`
|
||||
Enable bool `json:"enable" yaml:"enable"`
|
||||
Master string `json:"master" yaml:"master"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
Password string `json:"password,omitempty" yaml:"password,omitempty"`
|
||||
}
|
||||
|
||||
type ConnectionCluster struct {
|
||||
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`
|
||||
}
|
||||
|
|
|
@ -76,8 +76,10 @@ func (l *LogHook) DialHook(next redis.DialHook) redis.DialHook {
|
|||
|
||||
func (l *LogHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
|
||||
return func(ctx context.Context, cmd redis.Cmder) error {
|
||||
log.Println(cmd)
|
||||
t := time.Now()
|
||||
err := next(ctx, cmd)
|
||||
if l.cmdExec != nil {
|
||||
b := make([]byte, 0, 64)
|
||||
for i, arg := range cmd.Args() {
|
||||
if i > 0 {
|
||||
|
@ -85,8 +87,6 @@ func (l *LogHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
|
|||
}
|
||||
b = appendArg(b, arg)
|
||||
}
|
||||
log.Println(string(b))
|
||||
if l.cmdExec != nil {
|
||||
l.cmdExec(string(b), time.Since(t).Milliseconds())
|
||||
}
|
||||
return err
|
||||
|
@ -98,22 +98,19 @@ func (l *LogHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.Proc
|
|||
t := time.Now()
|
||||
err := next(ctx, cmds)
|
||||
cost := time.Since(t).Milliseconds()
|
||||
b := make([]byte, 0, 64)
|
||||
for _, cmd := range cmds {
|
||||
log.Println("pipeline: ", cmd)
|
||||
if l.cmdExec != nil {
|
||||
b := make([]byte, 0, 64)
|
||||
for i, arg := range cmd.Args() {
|
||||
if i > 0 {
|
||||
b = append(b, ' ')
|
||||
}
|
||||
b = appendArg(b, arg)
|
||||
}
|
||||
b = append(b, '\n')
|
||||
}
|
||||
}
|
||||
if l.cmdExec != nil {
|
||||
l.cmdExec(string(b), cost)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"tinyrdm/backend/types"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// ConvertTo convert string to specified type
|
||||
|
@ -188,9 +187,7 @@ func decodeJson(str string) (string, bool) {
|
|||
|
||||
func decodeBase64(str string) (string, bool) {
|
||||
if decodedStr, err := base64.StdEncoding.DecodeString(str); err == nil {
|
||||
if s := string(decodedStr); utf8.ValidString(s) {
|
||||
return s, true
|
||||
}
|
||||
return string(decodedStr), true
|
||||
}
|
||||
return str, false
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.10",
|
||||
"highlight.js": "^11.9.0",
|
||||
"highlight.js": "^11.8.0",
|
||||
"lodash": "^4.17.21",
|
||||
"pinia": "^2.1.7",
|
||||
"sass": "^1.69.3",
|
||||
"pinia": "^2.1.6",
|
||||
"sass": "^1.69.0",
|
||||
"vue": "^3.3.4",
|
||||
"vue-i18n": "^9.5.0"
|
||||
},
|
||||
|
@ -1048,9 +1048,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/highlight.js": {
|
||||
"version": "11.9.0",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.9.0.tgz",
|
||||
"integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==",
|
||||
"version": "11.8.0",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.8.0.tgz",
|
||||
"integrity": "sha512-MedQhoqVdr0U6SSnWPzfiadUcDHfN/Wzq25AkXiQv9oiOO/sG0S7XkvpFIqWBl9Yq1UYyYOOVORs5UW2XlPyzg==",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
|
@ -1393,9 +1393,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/pinia": {
|
||||
"version": "2.1.7",
|
||||
"resolved": "https://registry.npmmirror.com/pinia/-/pinia-2.1.7.tgz",
|
||||
"integrity": "sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==",
|
||||
"version": "2.1.6",
|
||||
"resolved": "https://registry.npmmirror.com/pinia/-/pinia-2.1.6.tgz",
|
||||
"integrity": "sha512-bIU6QuE5qZviMmct5XwCesXelb5VavdOWKWaB17ggk++NUwQWWbP5YnsONTk3b752QkW9sACiR81rorpeOMSvQ==",
|
||||
"dependencies": {
|
||||
"@vue/devtools-api": "^6.5.0",
|
||||
"vue-demi": ">=0.14.5"
|
||||
|
@ -1545,9 +1545,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/sass": {
|
||||
"version": "1.69.3",
|
||||
"resolved": "https://registry.npmmirror.com/sass/-/sass-1.69.3.tgz",
|
||||
"integrity": "sha512-X99+a2iGdXkdWn1akFPs0ZmelUzyAQfvqYc2P/MPTrJRuIRoTffGzT9W9nFqG00S+c8hXzVmgxhUuHFdrwxkhQ==",
|
||||
"version": "1.69.0",
|
||||
"resolved": "https://registry.npmmirror.com/sass/-/sass-1.69.0.tgz",
|
||||
"integrity": "sha512-l3bbFpfTOGgQZCLU/gvm1lbsQ5mC/WnLz3djL2v4WCJBDrWm58PO+jgngcGRNnKUh6wSsdm50YaovTqskZ0xDQ==",
|
||||
"dependencies": {
|
||||
"chokidar": ">=3.0.0 <4.0.0",
|
||||
"immutable": "^4.0.0",
|
||||
|
@ -2656,9 +2656,9 @@
|
|||
}
|
||||
},
|
||||
"highlight.js": {
|
||||
"version": "11.9.0",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.9.0.tgz",
|
||||
"integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw=="
|
||||
"version": "11.8.0",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.8.0.tgz",
|
||||
"integrity": "sha512-MedQhoqVdr0U6SSnWPzfiadUcDHfN/Wzq25AkXiQv9oiOO/sG0S7XkvpFIqWBl9Yq1UYyYOOVORs5UW2XlPyzg=="
|
||||
},
|
||||
"human-signals": {
|
||||
"version": "2.1.0",
|
||||
|
@ -2926,9 +2926,9 @@
|
|||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="
|
||||
},
|
||||
"pinia": {
|
||||
"version": "2.1.7",
|
||||
"resolved": "https://registry.npmmirror.com/pinia/-/pinia-2.1.7.tgz",
|
||||
"integrity": "sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==",
|
||||
"version": "2.1.6",
|
||||
"resolved": "https://registry.npmmirror.com/pinia/-/pinia-2.1.6.tgz",
|
||||
"integrity": "sha512-bIU6QuE5qZviMmct5XwCesXelb5VavdOWKWaB17ggk++NUwQWWbP5YnsONTk3b752QkW9sACiR81rorpeOMSvQ==",
|
||||
"requires": {
|
||||
"@vue/devtools-api": "^6.5.0",
|
||||
"vue-demi": ">=0.14.5"
|
||||
|
@ -3025,9 +3025,9 @@
|
|||
}
|
||||
},
|
||||
"sass": {
|
||||
"version": "1.69.3",
|
||||
"resolved": "https://registry.npmmirror.com/sass/-/sass-1.69.3.tgz",
|
||||
"integrity": "sha512-X99+a2iGdXkdWn1akFPs0ZmelUzyAQfvqYc2P/MPTrJRuIRoTffGzT9W9nFqG00S+c8hXzVmgxhUuHFdrwxkhQ==",
|
||||
"version": "1.69.0",
|
||||
"resolved": "https://registry.npmmirror.com/sass/-/sass-1.69.0.tgz",
|
||||
"integrity": "sha512-l3bbFpfTOGgQZCLU/gvm1lbsQ5mC/WnLz3djL2v4WCJBDrWm58PO+jgngcGRNnKUh6wSsdm50YaovTqskZ0xDQ==",
|
||||
"requires": {
|
||||
"chokidar": ">=3.0.0 <4.0.0",
|
||||
"immutable": "^4.0.0",
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.10",
|
||||
"highlight.js": "^11.9.0",
|
||||
"highlight.js": "^11.8.0",
|
||||
"lodash": "^4.17.21",
|
||||
"pinia": "^2.1.7",
|
||||
"sass": "^1.69.3",
|
||||
"pinia": "^2.1.6",
|
||||
"sass": "^1.69.0",
|
||||
"vue": "^3.3.4",
|
||||
"vue-i18n": "^9.5.0"
|
||||
},
|
||||
|
|
|
@ -1 +1 @@
|
|||
3b7cabd69c1c3dad11dea0682b3c6bef
|
||||
82f42b67ae979cb1af64c05c79c5251f
|
|
@ -1,7 +1,7 @@
|
|||
<script setup>
|
||||
import ContentPane from './components/content/ContentPane.vue'
|
||||
import BrowserPane from './components/sidebar/BrowserPane.vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { debounce, get } from 'lodash'
|
||||
import { useThemeVars } from 'naive-ui'
|
||||
import NavMenu from './components/sidebar/NavMenu.vue'
|
||||
|
@ -13,7 +13,7 @@ import useConnectionStore from './stores/connections.js'
|
|||
import ContentLogPane from './components/content/ContentLogPane.vue'
|
||||
import ContentValueTab from '@/components/content/ContentValueTab.vue'
|
||||
import ToolbarControlWidget from '@/components/common/ToolbarControlWidget.vue'
|
||||
import { EventsOn, WindowIsFullscreen, WindowIsMaximised, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js'
|
||||
import { WindowIsFullscreen, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js'
|
||||
import { isMacOS } from '@/utils/platform.js'
|
||||
import iconUrl from '@/assets/images/icon.png'
|
||||
|
||||
|
@ -37,11 +37,11 @@ const logPaneRef = ref(null)
|
|||
// const preferences = ref({})
|
||||
// provide('preferences', preferences)
|
||||
|
||||
const saveSidebarWidth = debounce(prefStore.savePreferences, 1000, { trailing: true })
|
||||
const saveWidth = debounce(prefStore.savePreferences, 1000, { trailing: true })
|
||||
const handleResize = (evt) => {
|
||||
if (data.resizing) {
|
||||
prefStore.setAsideWidth(Math.max(evt.clientX - data.navMenuWidth, 300))
|
||||
saveSidebarWidth()
|
||||
saveWidth()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ const stopResize = () => {
|
|||
data.resizing = false
|
||||
document.removeEventListener('mousemove', handleResize)
|
||||
document.removeEventListener('mouseup', stopResize)
|
||||
// TODO: Save sidebar x-position
|
||||
}
|
||||
|
||||
const startResize = () => {
|
||||
|
@ -74,54 +75,20 @@ watch(
|
|||
},
|
||||
)
|
||||
|
||||
const borderRadius = computed(() => {
|
||||
// FIXME: cannot get full screen status sync?
|
||||
// if (isMacOS()) {
|
||||
// return WindowIsFullscreen().then((full) => {
|
||||
// return full ? '0' : '10px'
|
||||
// })
|
||||
// }
|
||||
return '10px'
|
||||
})
|
||||
|
||||
const border = computed(() => {
|
||||
const color = isMacOS() && false ? '#0000' : themeVars.value.borderColor
|
||||
return `1px solid ${color}`
|
||||
})
|
||||
|
||||
const borderRadius = ref(10)
|
||||
const logoPaddingLeft = ref(10)
|
||||
const maximised = ref(false)
|
||||
const toggleWindowRadius = (on) => {
|
||||
borderRadius.value = on ? 10 : 0
|
||||
}
|
||||
|
||||
const onToggleFullscreen = (fullscreen) => {
|
||||
if (fullscreen) {
|
||||
logoPaddingLeft.value = 10
|
||||
toggleWindowRadius(false)
|
||||
} else {
|
||||
logoPaddingLeft.value = isMacOS() ? 70 : 10
|
||||
toggleWindowRadius(true)
|
||||
}
|
||||
}
|
||||
|
||||
const onToggleMaximize = (isMaximised) => {
|
||||
if (isMaximised) {
|
||||
maximised.value = true
|
||||
if (!isMacOS()) {
|
||||
toggleWindowRadius(false)
|
||||
}
|
||||
} else {
|
||||
maximised.value = false
|
||||
if (!isMacOS()) {
|
||||
toggleWindowRadius(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventsOn('window_changed', (info) => {
|
||||
const { fullscreen, maximised } = info
|
||||
onToggleFullscreen(fullscreen === true)
|
||||
onToggleMaximize(maximised)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
const fullscreen = await WindowIsFullscreen()
|
||||
onToggleFullscreen(fullscreen === true)
|
||||
const maximised = await WindowIsMaximised()
|
||||
onToggleMaximize(maximised)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -129,7 +96,7 @@ onMounted(async () => {
|
|||
<n-spin
|
||||
:show="props.loading"
|
||||
:theme-overrides="{ opacitySpinning: 0 }"
|
||||
:style="{ backgroundColor: themeVars.bodyColor, borderRadius: `${borderRadius}px`, border }">
|
||||
:style="{ backgroundColor: themeVars.bodyColor, borderRadius, border }">
|
||||
<div
|
||||
id="app-content-wrapper"
|
||||
class="flex-box-v"
|
||||
|
@ -149,7 +116,7 @@ onMounted(async () => {
|
|||
id="app-toolbar-title"
|
||||
:style="{
|
||||
width: `${data.navMenuWidth + prefStore.behavior.asideWidth - 4}px`,
|
||||
paddingLeft: `${logoPaddingLeft}px`,
|
||||
paddingLeft: isMacOS() ? '70px' : '10px',
|
||||
}">
|
||||
<n-space align="center" :wrap-item="false" :wrap="false" :size="3">
|
||||
<n-avatar :src="iconUrl" color="#0000" :size="35" style="min-width: 35px" />
|
||||
|
@ -176,11 +143,7 @@ onMounted(async () => {
|
|||
</div>
|
||||
<div class="flex-item-expand"></div>
|
||||
<!-- simulate window control buttons -->
|
||||
<toolbar-control-widget
|
||||
v-if="!isMacOS()"
|
||||
:size="data.toolbarHeight"
|
||||
:maximised="maximised"
|
||||
style="align-self: flex-start" />
|
||||
<toolbar-control-widget v-if="!isMacOS()" :size="data.toolbarHeight" style="align-self: flex-start" />
|
||||
</div>
|
||||
|
||||
<!-- content -->
|
||||
|
|
|
@ -4,8 +4,7 @@ import WindowMax from '@/components/icons/WindowMax.vue'
|
|||
import WindowClose from '@/components/icons/WindowClose.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useThemeVars } from 'naive-ui'
|
||||
import { Quit, WindowMinimise, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js'
|
||||
import WindowRestore from '@/components/icons/WindowRestore.vue'
|
||||
import { Quit, WindowIsMaximised, WindowMinimise, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js'
|
||||
|
||||
const themeVars = useThemeVars()
|
||||
const props = defineProps({
|
||||
|
@ -13,9 +12,6 @@ const props = defineProps({
|
|||
type: Number,
|
||||
default: 35,
|
||||
},
|
||||
maximised: {
|
||||
type: Boolean,
|
||||
},
|
||||
})
|
||||
|
||||
const buttonSize = computed(() => {
|
||||
|
@ -37,7 +33,7 @@ const handleClose = () => {
|
|||
|
||||
<template>
|
||||
<n-space :wrap-item="false" align="center" justify="center" :size="0">
|
||||
<n-tooltip :show-arrow="false" :delay="1000">
|
||||
<n-tooltip :show-arrow="false">
|
||||
{{ $t('menu.minimise') }}
|
||||
<template #trigger>
|
||||
<div class="btn-wrapper" @click="handleMinimise">
|
||||
|
@ -45,23 +41,15 @@ const handleClose = () => {
|
|||
</div>
|
||||
</template>
|
||||
</n-tooltip>
|
||||
<n-tooltip :show-arrow="false" :delay="1000" v-if="maximised">
|
||||
{{ $t('menu.restore') }}
|
||||
<template #trigger>
|
||||
<div class="btn-wrapper" @click="handleMaximise">
|
||||
<window-restore />
|
||||
</div>
|
||||
</template>
|
||||
</n-tooltip>
|
||||
<n-tooltip :show-arrow="false" :delay="1000" v-else>
|
||||
{{ $t('menu.maximise') }}
|
||||
<n-tooltip :show-arrow="false">
|
||||
{{ WindowIsMaximised() ? $t('menu.restore') : $t('menu.maximise') }}
|
||||
<template #trigger>
|
||||
<div class="btn-wrapper" @click="handleMaximise">
|
||||
<window-max />
|
||||
</div>
|
||||
</template>
|
||||
</n-tooltip>
|
||||
<n-tooltip :show-arrow="false" :delay="1000">
|
||||
<n-tooltip :show-arrow="false">
|
||||
{{ $t('menu.close') }}
|
||||
<template #trigger>
|
||||
<div class="btn-wrapper" @click="handleClose">
|
||||
|
|
|
@ -12,7 +12,7 @@ import useConnectionStore from 'stores/connections.js'
|
|||
import Copy from '@/components/icons/Copy.vue'
|
||||
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
|
||||
import { computed } from 'vue'
|
||||
import { isEmpty, padStart } from 'lodash'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
const props = defineProps({
|
||||
server: String,
|
||||
|
@ -51,23 +51,6 @@ const keyName = computed(() => {
|
|||
return !isEmpty(props.keyCode) ? props.keyCode : props.keyPath
|
||||
})
|
||||
|
||||
const ttlString = computed(() => {
|
||||
let s = ''
|
||||
if (props.ttl > 0) {
|
||||
const hours = Math.floor(props.ttl / 3600)
|
||||
s += padStart(hours + ':', 3, '0')
|
||||
const minutes = Math.floor((props.ttl % 3600) / 60)
|
||||
s += padStart(minutes + ':', 3, '0')
|
||||
const seconds = Math.floor(props.ttl % 60)
|
||||
s += padStart(seconds + '', 2, '0')
|
||||
} else if (props.ttl < 0) {
|
||||
s = i18n.t('interface.forever')
|
||||
} else {
|
||||
s = '00:00:00'
|
||||
}
|
||||
return s
|
||||
})
|
||||
|
||||
const onReloadKey = () => {
|
||||
connectionStore.loadKeyValue(props.server, props.db, keyName.value)
|
||||
}
|
||||
|
@ -121,10 +104,13 @@ const onDeleteKey = () => {
|
|||
<template #icon>
|
||||
<n-icon :component="Timer" size="18" />
|
||||
</template>
|
||||
{{ ttlString }}
|
||||
<template v-if="ttl < 0">
|
||||
{{ $t('interface.forever') }}
|
||||
</template>
|
||||
<template v-else>{{ ttl }} {{ $t('common.second') }}</template>
|
||||
</n-button>
|
||||
</template>
|
||||
TTL{{ `${ttl > 0 ? ': ' + ttl + $t('common.second') : ''}` }}
|
||||
TTL
|
||||
</n-tooltip>
|
||||
<icon-button :icon="Edit" border size="18" t-tooltip="interface.rename_key" @click="onRenameKey" />
|
||||
</n-button-group>
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
import { every, get, includes, isEmpty, map, sortBy, toNumber } from 'lodash'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ListSentinelMasters, TestConnection } from 'wailsjs/go/services/connectionService.js'
|
||||
import { ListSentinelMasters, SelectKeyFile, TestConnection } from 'wailsjs/go/services/connectionService.js'
|
||||
import useDialog, { ConnDialogType } from 'stores/dialog'
|
||||
import Close from '@/components/icons/Close.vue'
|
||||
import useConnectionStore from 'stores/connections.js'
|
||||
import { SelectFile } from 'wailsjs/go/services/systemService.js'
|
||||
|
||||
/**
|
||||
* Dialog for new or edit connection
|
||||
|
@ -83,36 +82,12 @@ const sshLoginType = computed(() => {
|
|||
return get(generalForm.value, 'ssh.loginType', 'pwd')
|
||||
})
|
||||
|
||||
const onSSHChooseKey = async () => {
|
||||
const { success, data } = await SelectFile()
|
||||
const path = get(data, 'path', '')
|
||||
if (!isEmpty(path)) {
|
||||
generalForm.value.ssh.pkFile = path
|
||||
}
|
||||
}
|
||||
|
||||
const onSSLChooseCert = async () => {
|
||||
const { success, data } = await SelectFile()
|
||||
const path = get(data, 'path', '')
|
||||
if (!isEmpty(path)) {
|
||||
generalForm.value.ssl.certFile = path
|
||||
}
|
||||
}
|
||||
|
||||
const onSSLChooseKey = async () => {
|
||||
const { success, data } = await SelectFile()
|
||||
const path = get(data, 'path', '')
|
||||
if (!isEmpty(path)) {
|
||||
generalForm.value.ssl.keyFile = path
|
||||
}
|
||||
}
|
||||
|
||||
const onSSLChooseCA = async () => {
|
||||
const { success, data } = await SelectFile()
|
||||
const onChoosePKFile = async () => {
|
||||
const { success, data } = await SelectKeyFile(i18n.t('dialogue.connection.ssh.pkfile_selection_title'))
|
||||
if (!success) {
|
||||
generalForm.value.ssl.caFile = ''
|
||||
generalForm.value.ssh.pkFile = ''
|
||||
} else {
|
||||
generalForm.value.ssl.caFile = get(data, 'path', '')
|
||||
generalForm.value.ssh.pkFile = get(data, 'path', '')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,13 +149,8 @@ const onSaveConnection = async () => {
|
|||
generalForm.value.dbFilterList = []
|
||||
}
|
||||
|
||||
// trim ssl data
|
||||
if (!!!generalForm.value.ssl.enable) {
|
||||
generalForm.value.ssl = {}
|
||||
}
|
||||
|
||||
// trim ssh login data
|
||||
if (!!generalForm.value.ssh.enable) {
|
||||
if (generalForm.value.ssh.enable) {
|
||||
switch (generalForm.value.ssh.loginType) {
|
||||
case 'pkfile':
|
||||
generalForm.value.ssh.password = ''
|
||||
|
@ -192,16 +162,15 @@ const onSaveConnection = async () => {
|
|||
}
|
||||
} else {
|
||||
// ssh disabled, reset to default value
|
||||
generalForm.value.ssh = {}
|
||||
const { ssh } = connectionStore.newDefaultConnection()
|
||||
generalForm.value.ssh = ssh
|
||||
}
|
||||
|
||||
// trim sentinel data
|
||||
if (!!!generalForm.value.sentinel.enable) {
|
||||
generalForm.value.sentinel = {}
|
||||
}
|
||||
|
||||
if (!!!generalForm.value.cluster.enable) {
|
||||
generalForm.value.cluster = {}
|
||||
if (!generalForm.value.sentinel.enable) {
|
||||
generalForm.value.sentinel.master = ''
|
||||
generalForm.value.sentinel.username = ''
|
||||
generalForm.value.sentinel.password = ''
|
||||
}
|
||||
|
||||
// store new connection
|
||||
|
@ -279,7 +248,6 @@ const onClose = () => {
|
|||
:show-icon="false"
|
||||
:title="isEditMode ? $t('dialogue.connection.edit_title') : $t('dialogue.connection.new_title')"
|
||||
preset="dialog"
|
||||
style="width: 600px"
|
||||
transform-origin="center">
|
||||
<n-spin :show="closingConnection">
|
||||
<n-tabs v-model:value="tab" animated type="line">
|
||||
|
@ -418,60 +386,6 @@ const onClose = () => {
|
|||
</n-form>
|
||||
</n-tab-pane>
|
||||
|
||||
<!-- SSL pane -->
|
||||
<n-tab-pane :tab="$t('dialogue.connection.ssl.title')" display-directive="show" name="ssl">
|
||||
<n-form-item label-placement="left">
|
||||
<n-checkbox v-model:checked="generalForm.ssl.enable" size="medium">
|
||||
{{ $t('dialogue.connection.ssl.enable') }}
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
<n-form
|
||||
:model="generalForm.ssl"
|
||||
:show-require-mark="false"
|
||||
:disabled="!generalForm.ssl.enable"
|
||||
label-placement="top">
|
||||
<n-form-item :label="$t('dialogue.connection.ssl.cert_file')">
|
||||
<n-input-group>
|
||||
<n-input
|
||||
v-model:value="generalForm.ssl.certFile"
|
||||
:placeholder="$t('dialogue.connection.ssl.cert_file_tip')"
|
||||
clearable />
|
||||
<n-button
|
||||
:focusable="false"
|
||||
:disabled="!generalForm.ssl.enable"
|
||||
@click="onSSLChooseCert">
|
||||
...
|
||||
</n-button>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
<n-form-item :label="$t('dialogue.connection.ssl.key_file')">
|
||||
<n-input-group>
|
||||
<n-input
|
||||
v-model:value="generalForm.ssl.keyFile"
|
||||
:placeholder="$t('dialogue.connection.ssl.key_file_tip')"
|
||||
clearable />
|
||||
<n-button
|
||||
:focusable="false"
|
||||
:disabled="!generalForm.ssl.enable"
|
||||
@click="onSSLChooseKey">
|
||||
...
|
||||
</n-button>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
<n-form-item :label="$t('dialogue.connection.ssl.ca_file')">
|
||||
<n-input-group>
|
||||
<n-input
|
||||
v-model:value="generalForm.ssl.caFile"
|
||||
:placeholder="$t('dialogue.connection.ssl.ca_file_tip')"
|
||||
clearable />
|
||||
<n-button :focusable="false" :disabled="!generalForm.ssl.enable" @click="onSSLChooseCA">
|
||||
...
|
||||
</n-button>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</n-tab-pane>
|
||||
|
||||
<!-- SSH pane -->
|
||||
<n-tab-pane :tab="$t('dialogue.connection.ssh.title')" display-directive="show" name="ssh">
|
||||
<n-form-item label-placement="left">
|
||||
|
@ -520,13 +434,7 @@ const onClose = () => {
|
|||
<n-input
|
||||
v-model:value="generalForm.ssh.pkFile"
|
||||
:placeholder="$t('dialogue.connection.ssh.pkfile_tip')" />
|
||||
<n-button
|
||||
:focusable="false"
|
||||
:disabled="!generalForm.ssh.enable"
|
||||
@click="onSSHChooseKey"
|
||||
clearable>
|
||||
...
|
||||
</n-button>
|
||||
<n-button :focusable="false" @click="onChoosePKFile">...</n-button>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="sshLoginType === 'pkfile'" :label="$t('dialogue.connection.ssh.passphrase')">
|
||||
|
@ -578,20 +486,8 @@ const onClose = () => {
|
|||
</n-form>
|
||||
</n-tab-pane>
|
||||
|
||||
<!-- Cluster pane -->
|
||||
<n-tab-pane :tab="$t('dialogue.connection.cluster.title')" display-directive="show" name="cluster">
|
||||
<n-form-item label-placement="left">
|
||||
<n-checkbox v-model:checked="generalForm.cluster.enable" size="medium">
|
||||
{{ $t('dialogue.connection.cluster.enable') }}
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
<!-- <n-form-->
|
||||
<!-- :model="generalForm.cluster"-->
|
||||
<!-- :show-require-mark="false"-->
|
||||
<!-- :disabled="!generalForm.cluster.enable"-->
|
||||
<!-- label-placement="top">-->
|
||||
<!-- </n-form>-->
|
||||
</n-tab-pane>
|
||||
<!-- TODO: SSL tab pane -->
|
||||
<!-- TODO: Cluster tab pane -->
|
||||
</n-tabs>
|
||||
|
||||
<!-- test result alert-->
|
||||
|
|
|
@ -31,7 +31,6 @@ watch(
|
|||
ttlForm.keyCode = tab.keyCode
|
||||
if (tab.ttl < 0) {
|
||||
// forever
|
||||
ttlForm.ttl = -1
|
||||
} else {
|
||||
ttlForm.ttl = tab.ttl
|
||||
}
|
||||
|
|
|
@ -1,187 +0,0 @@
|
|||
<script setup>
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
strokeWidth: {
|
||||
type: [Number, String],
|
||||
default: 3,
|
||||
},
|
||||
fillColor: {
|
||||
type: String,
|
||||
default: '#dc423c',
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg v-if="props.modelValue" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect
|
||||
x="4"
|
||||
y="34"
|
||||
width="8"
|
||||
height="8"
|
||||
:fill="props.fillColor"
|
||||
:stroke="props.fillColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<rect
|
||||
x="8"
|
||||
y="6"
|
||||
width="32"
|
||||
height="12"
|
||||
:fill="props.fillColor"
|
||||
:stroke="props.fillColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M24 34V18"
|
||||
:stroke="props.fillColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M8 34V26H40V34"
|
||||
:stroke="props.fillColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<rect
|
||||
x="36"
|
||||
y="34"
|
||||
width="8"
|
||||
height="8"
|
||||
:fill="props.fillColor"
|
||||
:stroke="props.fillColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<rect
|
||||
x="20"
|
||||
y="34"
|
||||
width="8"
|
||||
height="8"
|
||||
:fill="props.fillColor"
|
||||
:stroke="props.fillColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M14 12H16"
|
||||
stroke="#FFF"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
</svg>
|
||||
<svg v-else viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M5 24L43 24"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M28 4H20C18.8954 4 18 4.89543 18 6V14C18 15.1046 18.8954 16 20 16H28C29.1046 16 30 15.1046 30 14V6C30 4.89543 29.1046 4 28 4Z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M16 32H8C6.89543 32 6 32.8954 6 34V42C6 43.1046 6.89543 44 8 44H16C17.1046 44 18 43.1046 18 42V34C18 32.8954 17.1046 32 16 32Z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M40 32H32C30.8954 32 30 32.8954 30 34V42C30 43.1046 30.8954 44 32 44H40C41.1046 44 42 43.1046 42 42V34C42 32.8954 41.1046 32 40 32Z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M24 24V16"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M36 32V24"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M12 32V24"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
</svg>
|
||||
<svg v-else viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect
|
||||
x="4"
|
||||
y="34"
|
||||
width="8"
|
||||
height="8"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<rect
|
||||
x="8"
|
||||
y="6"
|
||||
width="32"
|
||||
height="12"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M24 34V18"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M8 34V26H40V34"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<rect
|
||||
x="36"
|
||||
y="34"
|
||||
width="8"
|
||||
height="8"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<rect
|
||||
x="20"
|
||||
y="34"
|
||||
width="8"
|
||||
height="8"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M14 12H16"
|
||||
stroke="currentColor"
|
||||
:stroke-width="props.strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
|
@ -2,15 +2,17 @@
|
|||
const props = defineProps({
|
||||
size: {
|
||||
type: [Number, String],
|
||||
default: 14,
|
||||
default: 12,
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg :width="props.size" :height="props.size" viewBox="0 0 48 48" fill="none">
|
||||
<path d="M8 8L40 40" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<path d="M8 40L40 8" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<svg aria-hidden="false" :width="props.size" :height="props.size" viewBox="0 0 12 12">
|
||||
<polygon
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
points="11 1.576 6.583 6 11 10.424 10.424 11 6 6.583 1.576 11 1 10.424 5.417 6 1 1.576 1.576 1 6 5.417 10.424 1"></polygon>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -2,18 +2,14 @@
|
|||
const props = defineProps({
|
||||
size: {
|
||||
type: [Number, String],
|
||||
default: 14,
|
||||
default: 12,
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg :width="props.size" :height="props.size" viewBox="0 0 48 48" fill="none">
|
||||
<path
|
||||
d="M39 6H9C7.34315 6 6 7.34315 6 9V39C6 40.6569 7.34315 42 9 42H39C40.6569 42 42 40.6569 42 39V9C42 7.34315 40.6569 6 39 6Z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="4" />
|
||||
<svg aria-hidden="false" :width="props.size" :height="props.size" viewBox="0 0 12 12">
|
||||
<rect width="9" height="9" x="1.5" y="1.5" fill="none" stroke="currentColor"></rect>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
const props = defineProps({
|
||||
size: {
|
||||
type: [Number, String],
|
||||
default: 14,
|
||||
default: 12,
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg :width="props.size" :height="props.size" viewBox="0 0 48 48" fill="none">
|
||||
<path d="M8 24L40 24" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<svg aria-hidden="false" :width="props.size" :height="props.size" viewBox="0 0 12 12">
|
||||
<rect fill="currentColor" width="10" height="1" x="1" y="6"></rect>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<script setup>
|
||||
const props = defineProps({
|
||||
size: {
|
||||
type: [Number, String],
|
||||
default: 14,
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg :width="props.size" :height="props.size" viewBox="0 0 48 48" fill="none">
|
||||
<path
|
||||
d="M13 12.4316V7.8125C13 6.2592 14.2592 5 15.8125 5H40.1875C41.7408 5 43 6.2592 43 7.8125V32.1875C43 33.7408 41.7408 35 40.1875 35H35.5163"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round" />
|
||||
<path
|
||||
d="M32.1875 13H7.8125C6.2592 13 5 14.2592 5 15.8125V40.1875C5 41.7408 6.2592 43 7.8125 43H32.1875C33.7408 43 35 41.7408 35 40.1875V15.8125C35 14.2592 33.7408 13 32.1875 13Z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
stroke-linejoin="round" />
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
|
@ -5,7 +5,7 @@ import { NIcon, NSpace, NTag } from 'naive-ui'
|
|||
import Key from '@/components/icons/Key.vue'
|
||||
import Binary from '@/components/icons/Binary.vue'
|
||||
import ToggleDb from '@/components/icons/ToggleDb.vue'
|
||||
import { find, get, includes, indexOf, isEmpty, remove, size } from 'lodash'
|
||||
import { find, get, includes, indexOf, isEmpty, pull, remove, size } from 'lodash'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Refresh from '@/components/icons/Refresh.vue'
|
||||
import CopyLink from '@/components/icons/CopyLink.vue'
|
||||
|
@ -16,6 +16,7 @@ import Connect from '@/components/icons/Connect.vue'
|
|||
import useDialogStore from 'stores/dialog.js'
|
||||
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
|
||||
import useConnectionStore from 'stores/connections.js'
|
||||
import ToggleServer from '@/components/icons/ToggleServer.vue'
|
||||
import Unlink from '@/components/icons/Unlink.vue'
|
||||
import Filter from '@/components/icons/Filter.vue'
|
||||
import Close from '@/components/icons/Close.vue'
|
||||
|
@ -347,15 +348,14 @@ const onUpdateSelectedKeys = (keys, options) => {
|
|||
|
||||
const renderPrefix = ({ option }) => {
|
||||
switch (option.type) {
|
||||
// case ConnectionType.Server:
|
||||
// const icon = option.cluster === true ? ToggleCluster : ToggleServer
|
||||
// return h(
|
||||
// NIcon,
|
||||
// { size: 20 },
|
||||
// {
|
||||
// default: () => h(icon, { modelValue: false }),
|
||||
// },
|
||||
// )
|
||||
case ConnectionType.Server:
|
||||
return h(
|
||||
NIcon,
|
||||
{ size: 20 },
|
||||
{
|
||||
default: () => h(ToggleServer, { modelValue: false }),
|
||||
},
|
||||
)
|
||||
case ConnectionType.RedisDB:
|
||||
return h(
|
||||
NIcon,
|
||||
|
|
|
@ -6,7 +6,6 @@ import { NIcon, NSpace, NText, useThemeVars } from 'naive-ui'
|
|||
import { ConnectionType } from '@/consts/connection_type.js'
|
||||
import ToggleFolder from '@/components/icons/ToggleFolder.vue'
|
||||
import ToggleServer from '@/components/icons/ToggleServer.vue'
|
||||
import ToggleCluster from '@/components/icons/ToggleCluster.vue'
|
||||
import { debounce, get, includes, indexOf, isEmpty, split } from 'lodash'
|
||||
import Config from '@/components/icons/Config.vue'
|
||||
import Delete from '@/components/icons/Delete.vue'
|
||||
|
@ -194,13 +193,12 @@ const renderPrefix = ({ option }) => {
|
|||
case ConnectionType.Server:
|
||||
const connected = connectionStore.isConnected(option.name)
|
||||
const color = getServerMarkColor(option.name)
|
||||
const icon = option.cluster === true ? ToggleCluster : ToggleServer
|
||||
return h(
|
||||
NIcon,
|
||||
{ size: 20, color: !!!connected ? color : undefined },
|
||||
{
|
||||
default: () =>
|
||||
h(icon, {
|
||||
h(ToggleServer, {
|
||||
modelValue: !!connected,
|
||||
fillColor: `rgba(220,66,60,${iconTransparency})`,
|
||||
}),
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
},
|
||||
"ribbon": {
|
||||
"server": "Server",
|
||||
"browser": "Data Browser",
|
||||
"browser": "Browser",
|
||||
"log": "Log"
|
||||
},
|
||||
"dialogue": {
|
||||
|
@ -147,16 +147,6 @@
|
|||
"dbfilter_input_tip": "Press Enter to confirm",
|
||||
"mark_color": "Mark Color"
|
||||
},
|
||||
"ssl": {
|
||||
"title": "SSL/TLS",
|
||||
"enable": "Enable SSL/TLS",
|
||||
"cert_file": "Public Key",
|
||||
"key_file": "Private Key",
|
||||
"ca_file": "Authority",
|
||||
"cert_file_tip":"Public Key File in PEM format(Cert)",
|
||||
"key_file_tip": "Private Key File in PEM format(Key)",
|
||||
"ca_file_tip": "Certificate Authority File in PEM format(CA)"
|
||||
},
|
||||
"ssh": {
|
||||
"title": "SSH Tunnel",
|
||||
"enable": "Enable SSH Tuntel",
|
||||
|
@ -167,7 +157,8 @@
|
|||
"usr_tip": "SSH Username",
|
||||
"pwd_tip": "SSH Password",
|
||||
"pkfile_tip": "SSH Private Key File Path",
|
||||
"passphrase_tip": "(Optional) Passphrase for Private Key"
|
||||
"passphrase_tip": "(Optional) Passphrase for Private Key",
|
||||
"pkfile_selection_title": "Please Select Private Key File"
|
||||
},
|
||||
"sentinel": {
|
||||
"title": "Sentinel",
|
||||
|
@ -178,11 +169,6 @@
|
|||
"username": "Username for Master Node",
|
||||
"pwd_tip": "(Optional) Authentication username for master node",
|
||||
"usr_tip": "(Optional) Authentication password for master node (Redis > 6.0)"
|
||||
},
|
||||
"cluster": {
|
||||
"title": "Cluster",
|
||||
"enable": "Serve as Cluster Node",
|
||||
"readonly": "Enables read-only commands on slave nodes"
|
||||
}
|
||||
},
|
||||
"group": {
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
},
|
||||
"ribbon": {
|
||||
"server": "服务器",
|
||||
"browser": "数据浏览",
|
||||
"browser": "浏览器",
|
||||
"log": "日志"
|
||||
},
|
||||
"dialogue": {
|
||||
|
@ -147,16 +147,6 @@
|
|||
"dbfilter_input_tip": "按回车确认",
|
||||
"mark_color": "标记颜色"
|
||||
},
|
||||
"ssl": {
|
||||
"title": "SSL/TLS",
|
||||
"enable": "启用SSL",
|
||||
"cert_file": "公钥文件",
|
||||
"key_file": "私钥文件",
|
||||
"ca_file": "授权文件",
|
||||
"cert_file_tip":"PEM格式公钥文件(Cert)",
|
||||
"key_file_tip": "PEM格式私钥文件(Key)",
|
||||
"ca_file_tip": "PEM格式授权文件(CA)"
|
||||
},
|
||||
"ssh": {
|
||||
"enable": "启用SSH隧道",
|
||||
"title": "SSH隧道",
|
||||
|
@ -167,7 +157,8 @@
|
|||
"usr_tip": "SSH登录用户名",
|
||||
"pwd_tip": "SSH登录密码",
|
||||
"pkfile_tip": "SSH私钥文件路径",
|
||||
"passphrase_tip": "(可选)SSH私钥密码"
|
||||
"passphrase_tip": "(可选)SSH私钥密码",
|
||||
"pkfile_selection_title": "请选择私钥文件"
|
||||
},
|
||||
"sentinel": {
|
||||
"title": "哨兵模式",
|
||||
|
@ -178,10 +169,6 @@
|
|||
"username": "主节点用户名",
|
||||
"pwd_tip": "(可选)主节点服务授权用户名",
|
||||
"usr_tip": "(可选)主节点服务授权密码 (Redis > 6.0)"
|
||||
},
|
||||
"cluster": {
|
||||
"title": "集群模式",
|
||||
"enable": "当前为集群节点"
|
||||
}
|
||||
},
|
||||
"group": {
|
||||
|
|
|
@ -59,7 +59,6 @@ const useConnectionStore = defineStore('connections', {
|
|||
* @property {string} label display label
|
||||
* @property {string} name database name
|
||||
* @property {number} type
|
||||
* @property {boolean} cluster is cluster node
|
||||
* @property {ConnectionItem[]} children
|
||||
*/
|
||||
|
||||
|
@ -147,7 +146,6 @@ const useConnectionStore = defineStore('connections', {
|
|||
label: conn.name,
|
||||
name: conn.name,
|
||||
type: ConnectionType.Server,
|
||||
cluster: get(conn, 'cluster.enable', false),
|
||||
// isLeaf: false,
|
||||
})
|
||||
profiles[conn.name] = {
|
||||
|
@ -167,7 +165,6 @@ const useConnectionStore = defineStore('connections', {
|
|||
label: item.name,
|
||||
name: item.name,
|
||||
type: ConnectionType.Server,
|
||||
cluster: get(item, 'cluster.enable', false),
|
||||
// isLeaf: false,
|
||||
})
|
||||
profiles[item.name] = {
|
||||
|
@ -231,12 +228,6 @@ const useConnectionStore = defineStore('connections', {
|
|||
dbFilterType: 'none',
|
||||
dbFilterList: [],
|
||||
markColor: '',
|
||||
ssl: {
|
||||
enable: false,
|
||||
certFile: '',
|
||||
keyFile: '',
|
||||
caFile: '',
|
||||
},
|
||||
ssh: {
|
||||
enable: false,
|
||||
addr: '',
|
||||
|
@ -253,9 +244,6 @@ const useConnectionStore = defineStore('connections', {
|
|||
username: '',
|
||||
password: '',
|
||||
},
|
||||
cluster: {
|
||||
enable: false,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -636,7 +624,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
}
|
||||
// its danger to delete "non-exists" key, just remove from tree view
|
||||
await this.deleteKey(server, db, key, true)
|
||||
// TODO: show key not found page or check exists on server first?
|
||||
// TODO: show key not found page?
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
main.go
15
main.go
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/wailsapp/wails/v2/pkg/options/linux"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/mac"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/windows"
|
||||
runtime2 "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"runtime"
|
||||
"tinyrdm/backend/consts"
|
||||
"tinyrdm/backend/services"
|
||||
|
@ -25,7 +26,7 @@ var version = "0.0.0"
|
|||
|
||||
func main() {
|
||||
// Create an instance of the app structure
|
||||
sysSvc := services.System()
|
||||
app := NewApp()
|
||||
connSvc := services.Connection()
|
||||
prefSvc := services.Preferences()
|
||||
prefSvc.SetAppVersion(version)
|
||||
|
@ -53,14 +54,22 @@ func main() {
|
|||
},
|
||||
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 0},
|
||||
OnStartup: func(ctx context.Context) {
|
||||
sysSvc.Start(ctx)
|
||||
app.startup(ctx)
|
||||
connSvc.Start(ctx)
|
||||
},
|
||||
OnBeforeClose: func(ctx context.Context) (prevent bool) {
|
||||
// save current window size
|
||||
width, height := runtime2.WindowGetSize(ctx)
|
||||
if width > 0 && height > 0 {
|
||||
prefSvc.SaveWindowSize(width, height)
|
||||
}
|
||||
return false
|
||||
},
|
||||
OnShutdown: func(ctx context.Context) {
|
||||
connSvc.Stop(ctx)
|
||||
},
|
||||
Bind: []interface{}{
|
||||
sysSvc,
|
||||
app,
|
||||
connSvc,
|
||||
prefSvc,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue