Compare commits
3 Commits
30e7016aa3
...
97f6ded7e0
Author | SHA1 | Date |
---|---|---|
tiny-craft | 97f6ded7e0 | |
tiny-craft | ab2056ba3e | |
tiny-craft | b3c494f15e |
|
@ -328,7 +328,7 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) {
|
||||||
selConn := c.conns.GetConnection(name)
|
selConn := c.conns.GetConnection(name)
|
||||||
|
|
||||||
totaldb := 16
|
totaldb := 16
|
||||||
if selConn.DBFilterType == "none" {
|
if selConn.DBFilterType == "" || selConn.DBFilterType == "none" {
|
||||||
// get total databases
|
// get total databases
|
||||||
if config, err := rdb.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 {
|
if total, err := strconv.Atoi(config["databases"]); err == nil {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"tinyrdm/backend/consts"
|
||||||
"tinyrdm/backend/types"
|
"tinyrdm/backend/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +46,9 @@ func (p *PreferencesStorage) GetPreferences() (ret types.Preferences) {
|
||||||
defer p.mutex.Unlock()
|
defer p.mutex.Unlock()
|
||||||
|
|
||||||
ret = p.getPreferences()
|
ret = p.getPreferences()
|
||||||
|
ret.Behavior.AsideWidth = max(ret.Behavior.AsideWidth, consts.DEFAULT_ASIDE_WIDTH)
|
||||||
|
ret.Behavior.WindowWidth = max(ret.Behavior.WindowWidth, consts.DEFAULT_WINDOW_WIDTH)
|
||||||
|
ret.Behavior.WindowHeight = max(ret.Behavior.WindowHeight, consts.DEFAULT_WINDOW_HEIGHT)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,3 +9,6 @@ const BINARY = "Binary"
|
||||||
const GZIP = "GZip"
|
const GZIP = "GZip"
|
||||||
const GZIP_JSON = "GZip JSON"
|
const GZIP_JSON = "GZip JSON"
|
||||||
const DEFLATE = "Deflate"
|
const DEFLATE = "Deflate"
|
||||||
|
const DEFLATE_JSON = "Deflate JSON"
|
||||||
|
const BROTLI = "Brotli"
|
||||||
|
const BROTLI_JSON = "Brotli JSON"
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/andybalholm/brotli"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -72,7 +73,7 @@ func ConvertTo(str, targetType string) (value, resultType string) {
|
||||||
|
|
||||||
case types.GZIP, types.GZIP_JSON:
|
case types.GZIP, types.GZIP_JSON:
|
||||||
if gzipStr, ok := decodeGZip(str); ok {
|
if gzipStr, ok := decodeGZip(str); ok {
|
||||||
if targetType == types.BASE64_JSON {
|
if targetType == types.GZIP_JSON {
|
||||||
value, _ = decodeJson(gzipStr)
|
value, _ = decodeJson(gzipStr)
|
||||||
} else {
|
} else {
|
||||||
value = gzipStr
|
value = gzipStr
|
||||||
|
@ -83,8 +84,29 @@ func ConvertTo(str, targetType string) (value, resultType string) {
|
||||||
resultType = targetType
|
resultType = targetType
|
||||||
return
|
return
|
||||||
|
|
||||||
case types.DEFLATE:
|
case types.DEFLATE, types.DEFLATE_JSON:
|
||||||
value, _ = decodeDeflate(str)
|
if deflateStr, ok := decodeDeflate(str); ok {
|
||||||
|
if targetType == types.DEFLATE_JSON {
|
||||||
|
value, _ = decodeJson(deflateStr)
|
||||||
|
} else {
|
||||||
|
value = deflateStr
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = str
|
||||||
|
}
|
||||||
|
resultType = targetType
|
||||||
|
return
|
||||||
|
|
||||||
|
case types.BROTLI, types.BROTLI_JSON:
|
||||||
|
if brotliStr, ok := decodeBrotli(str); ok {
|
||||||
|
if targetType == types.BROTLI_JSON {
|
||||||
|
value, _ = decodeJson(brotliStr)
|
||||||
|
} else {
|
||||||
|
value = brotliStr
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = str
|
||||||
|
}
|
||||||
resultType = targetType
|
resultType = targetType
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -122,10 +144,23 @@ func autoToType(str string) (value, resultType string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if value, ok = decodeDeflate(str); ok {
|
if value, ok = decodeDeflate(str); ok {
|
||||||
|
if value, ok = decodeJson(value); ok {
|
||||||
|
resultType = types.DEFLATE_JSON
|
||||||
|
return
|
||||||
|
}
|
||||||
resultType = types.DEFLATE
|
resultType = types.DEFLATE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if value, ok = decodeBrotli(str); ok {
|
||||||
|
if value, ok = decodeJson(value); ok {
|
||||||
|
resultType = types.BROTLI_JSON
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resultType = types.BROTLI
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if isBinary(str) {
|
if isBinary(str) {
|
||||||
if value, ok = decodeHex(str); ok {
|
if value, ok = decodeHex(str); ok {
|
||||||
resultType = types.HEX
|
resultType = types.HEX
|
||||||
|
@ -207,6 +242,14 @@ func decodeDeflate(str string) (string, bool) {
|
||||||
return str, false
|
return str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeBrotli(str string) (string, bool) {
|
||||||
|
reader := brotli.NewReader(strings.NewReader(str))
|
||||||
|
if decompressed, err := io.ReadAll(reader); err == nil {
|
||||||
|
return string(decompressed), true
|
||||||
|
}
|
||||||
|
return str, false
|
||||||
|
}
|
||||||
|
|
||||||
func SaveAs(str, targetType string) (value string, err error) {
|
func SaveAs(str, targetType string) (value string, err error) {
|
||||||
switch targetType {
|
switch targetType {
|
||||||
case types.PLAIN_TEXT:
|
case types.PLAIN_TEXT:
|
||||||
|
@ -224,7 +267,7 @@ func SaveAs(str, targetType string) (value string, err error) {
|
||||||
binStr, _ := encodeBinary(str)
|
binStr, _ := encodeBinary(str)
|
||||||
return binStr, nil
|
return binStr, nil
|
||||||
|
|
||||||
case types.JSON, types.BASE64_JSON, types.GZIP_JSON:
|
case types.JSON, types.BASE64_JSON, types.GZIP_JSON, types.DEFLATE_JSON, types.BROTLI_JSON:
|
||||||
if jsonStr, ok := encodeJson(str); ok {
|
if jsonStr, ok := encodeJson(str); ok {
|
||||||
switch targetType {
|
switch targetType {
|
||||||
case types.BASE64_JSON:
|
case types.BASE64_JSON:
|
||||||
|
@ -233,6 +276,12 @@ func SaveAs(str, targetType string) (value string, err error) {
|
||||||
case types.GZIP_JSON:
|
case types.GZIP_JSON:
|
||||||
gzipStr, _ := encodeGZip(jsonStr)
|
gzipStr, _ := encodeGZip(jsonStr)
|
||||||
return gzipStr, nil
|
return gzipStr, nil
|
||||||
|
case types.DEFLATE_JSON:
|
||||||
|
deflateStr, _ := encodeDeflate(jsonStr)
|
||||||
|
return deflateStr, nil
|
||||||
|
case types.BROTLI_JSON:
|
||||||
|
brotliStr, _ := encodeBrotli(jsonStr)
|
||||||
|
return brotliStr, nil
|
||||||
default:
|
default:
|
||||||
return jsonStr, nil
|
return jsonStr, nil
|
||||||
}
|
}
|
||||||
|
@ -253,6 +302,13 @@ func SaveAs(str, targetType string) (value string, err error) {
|
||||||
} else {
|
} else {
|
||||||
return str, errors.New("fail to build deflate data")
|
return str, errors.New("fail to build deflate data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case types.BROTLI:
|
||||||
|
if brotliStr, ok := encodeBrotli(str); ok {
|
||||||
|
return brotliStr, nil
|
||||||
|
} else {
|
||||||
|
return str, errors.New("fail to build brotli data")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return str, errors.New("fail to save with unknown error")
|
return str, errors.New("fail to save with unknown error")
|
||||||
}
|
}
|
||||||
|
@ -332,3 +388,20 @@ func encodeDeflate(str string) (string, bool) {
|
||||||
}
|
}
|
||||||
return str, false
|
return str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodeBrotli(str string) (string, bool) {
|
||||||
|
var compress = func(b []byte) (string, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
writer := brotli.NewWriter(&buf)
|
||||||
|
if _, err := writer.Write([]byte(str)); err != nil {
|
||||||
|
writer.Close()
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
writer.Close()
|
||||||
|
return string(buf.Bytes()), nil
|
||||||
|
}
|
||||||
|
if brotliStr, err := compress([]byte(str)); err == nil {
|
||||||
|
return brotliStr, true
|
||||||
|
}
|
||||||
|
return str, false
|
||||||
|
}
|
||||||
|
|
|
@ -67,6 +67,8 @@ const viewLanguage = computed(() => {
|
||||||
case types.JSON:
|
case types.JSON:
|
||||||
case types.BASE64_JSON:
|
case types.BASE64_JSON:
|
||||||
case types.GZIP_JSON:
|
case types.GZIP_JSON:
|
||||||
|
case types.DEFLATE_JSON:
|
||||||
|
case types.BROTLI_JSON:
|
||||||
return 'json'
|
return 'json'
|
||||||
default:
|
default:
|
||||||
return 'plaintext'
|
return 'plaintext'
|
||||||
|
@ -144,6 +146,7 @@ const onSaveValue = async () => {
|
||||||
:value="props.viewAs"
|
:value="props.viewAs"
|
||||||
:options="viewOption"
|
:options="viewOption"
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
|
filterable
|
||||||
@update:value="onViewTypeUpdate" />
|
@update:value="onViewTypeUpdate" />
|
||||||
<div class="flex-item-expand"></div>
|
<div class="flex-item-expand"></div>
|
||||||
<n-button-group v-if="!inEdit">
|
<n-button-group v-if="!inEdit">
|
||||||
|
|
|
@ -12,4 +12,7 @@ export const types = {
|
||||||
GZIP: 'GZip',
|
GZIP: 'GZip',
|
||||||
GZIP_JSON: 'GZip JSON',
|
GZIP_JSON: 'GZip JSON',
|
||||||
DEFLATE: 'Deflate',
|
DEFLATE: 'Deflate',
|
||||||
|
DEFLATE_JSON: 'Deflate JSON',
|
||||||
|
BROTLI: 'Brotli',
|
||||||
|
BROTLI_JSON: 'Brotli JSON',
|
||||||
}
|
}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -4,6 +4,7 @@ go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/adrg/sysfont v0.1.2
|
github.com/adrg/sysfont v0.1.2
|
||||||
|
github.com/andybalholm/brotli v1.0.5
|
||||||
github.com/redis/go-redis/v9 v9.2.1
|
github.com/redis/go-redis/v9 v9.2.1
|
||||||
github.com/vrischmann/userdir v0.0.0-20151206171402-20f291cebd68
|
github.com/vrischmann/userdir v0.0.0-20151206171402-20f291cebd68
|
||||||
github.com/wailsapp/wails/v2 v2.6.0
|
github.com/wailsapp/wails/v2 v2.6.0
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -6,6 +6,8 @@ github.com/adrg/sysfont v0.1.2/go.mod h1:6d3l7/BSjX9VaeXWJt9fcrftFaD/t7l11xgSywC
|
||||||
github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
|
github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
|
||||||
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
|
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
|
||||||
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
|
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
|
||||||
|
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||||
|
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||||
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||||
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
|
16
main.go
16
main.go
|
@ -57,23 +57,15 @@ func main() {
|
||||||
app.startup(ctx)
|
app.startup(ctx)
|
||||||
connSvc.Start(ctx)
|
connSvc.Start(ctx)
|
||||||
},
|
},
|
||||||
//OnBeforeClose: func(ctx context.Context) (prevent bool) {
|
OnBeforeClose: func(ctx context.Context) (prevent bool) {
|
||||||
// // save current window size
|
|
||||||
// width, height := runtime2.WindowGetSize(ctx)
|
|
||||||
// if width > 0 && height > 0 {
|
|
||||||
// if w, h := prefSvc.GetWindowSize(); w != width || h != height {
|
|
||||||
// prefSvc.SaveWindowSize(width, height)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false
|
|
||||||
//},
|
|
||||||
OnShutdown: func(ctx context.Context) {
|
|
||||||
// save current window size
|
// save current window size
|
||||||
width, height := runtime2.WindowGetSize(ctx)
|
width, height := runtime2.WindowGetSize(ctx)
|
||||||
if width > 0 && height > 0 {
|
if width > 0 && height > 0 {
|
||||||
prefSvc.SaveWindowSize(width, height)
|
prefSvc.SaveWindowSize(width, height)
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
OnShutdown: func(ctx context.Context) {
|
||||||
connSvc.Stop(ctx)
|
connSvc.Stop(ctx)
|
||||||
},
|
},
|
||||||
Bind: []interface{}{
|
Bind: []interface{}{
|
||||||
|
|
Loading…
Reference in New Issue