Skip to content

Commit

Permalink
Merge branch 'tiny-craft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
huangliu authored May 24, 2024
2 parents a787d1a + 4ed9390 commit b472cb7
Show file tree
Hide file tree
Showing 70 changed files with 2,046 additions and 1,395 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
release:
name: Release Linux App
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
strategy:
matrix:
platform:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
shell: bash
run: |
CGO_ENABLED=1 wails build -platform ${{ matrix.platform }} \
-ldflags "-X main.version=${{ github.event.release.tag_name }} -X main.gaMeasurementID=${{ secrets.GA_MEASUREMENT_ID }} -X main.gaSecretKey=${{ secrets.MAC_GA_SECRET }}"
-ldflags "-X main.version=${{ steps.normalise_version.outputs.version }} -X main.gaMeasurementID=${{ secrets.GA_MEASUREMENT_ID }} -X main.gaSecretKey=${{ secrets.MAC_GA_SECRET }}"
# - name: Notarise macOS app + create dmg
# shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
- name: Rename installer
working-directory: ./build/bin
run: Rename-Item -Path "TinyRDM-${{ matrix.platform }}-installer.exe" -NewName "TinyRDM_Setup_${{ steps.normalise_version.outputs.version }}_${{ steps.platform_name.outputs.tag }}.exe"
run: Rename-Item -Path "TinyRDM-${{ steps.normalise_platform_name.outputs.pname }}-installer.exe" -NewName "TinyRDM_Setup_${{ steps.normalise_version.outputs.version }}_${{ steps.normalise_platform.outputs.tag }}.exe"

- name: Upload release asset (Installer)
uses: softprops/action-gh-release@v1
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Linux.</strong>
* Support import/export data.
* Support publish/subscribe.
* Support import/export connection profile.
* Custom data encoder and decoder for value display.
* Custom data encoder and decoder for value display ([Here are the instructions](https://redis.tinycraft.cc/guide/custom-decoder/)).

## Installation

Expand Down Expand Up @@ -88,6 +88,13 @@ git clone https://github.com/tiny-craft/tiny-rdm --depth=1
npm install --prefix ./frontend
```

or

```bash
cd frontend
npm install
```

### Compile and Run

```bash
Expand Down
13 changes: 12 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* 支持导入/导出数据
* 支持发布订阅
* 支持导入/导出连接配置
* 自定义数据展示编码/解码
* 自定义数据展示编码/解码([这是操作指引](https://redis.tinycraft.cc/zh/guide/custom-decoder/))

## 安装

Expand Down Expand Up @@ -83,6 +83,13 @@ git clone https://github.com/tiny-craft/tiny-rdm --depth=1
npm install --prefix ./frontend
```

或者

```bash
cd frontend
npm install
```

### 编译运行开发版本

```bash
Expand All @@ -99,6 +106,10 @@ wails dev

<img src="docs/images/wechat_official.png" alt="wechat" width="360" />

### B站官方账号

<img src="docs/images/bilibili_official.png" alt="bilibili" width="360" />

### 独立开发互助QQ群

```
Expand Down
55 changes: 46 additions & 9 deletions backend/services/browser_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,45 @@ func (b *browserService) SetKeyValue(param types.SetKeyParam) (resp types.JSResp
return
}

// GetHashValue get hash field
func (b *browserService) GetHashValue(param types.GetHashParam) (resp types.JSResp) {
item, err := b.getRedisClient(param.Server, param.DB)
if err != nil {
resp.Msg = err.Error()
return
}

client, ctx := item.client, item.ctx
key := strutil.DecodeRedisKey(param.Key)
val, err := client.HGet(ctx, key, param.Field).Result()
if errors.Is(err, redis.Nil) {
resp.Msg = "field in key not found"
return
}
if err != nil {
resp.Msg = err.Error()
return
}

var displayVal string
if (len(param.Decode) > 0 && param.Decode != types.DECODE_NONE) ||
(len(param.Format) > 0 && param.Format != types.FORMAT_RAW) {
decoder := Preferences().GetDecoder()
displayVal, _, _ = convutil.ConvertTo(val, param.Decode, param.Format, decoder)
if displayVal == val {
displayVal = ""
}
}

resp.Data = types.HashEntryItem{
Key: param.Field,
Value: val,
DisplayValue: displayVal,
}
resp.Success = true
return
}

// SetHashValue update hash field
func (b *browserService) SetHashValue(param types.SetHashParam) (resp types.JSResp) {
item, err := b.getRedisClient(param.Server, param.DB)
Expand Down Expand Up @@ -2070,8 +2109,8 @@ func (b *browserService) DeleteKey(server string, db int, k any, async bool) (re
handleDel := func(ks []string) error {
var delErr error
if async && supportUnlink {
supportUnlink = false
if delErr = cli.Unlink(ctx, ks...).Err(); delErr != nil {
supportUnlink = false
// not support unlink? try del command
delErr = cli.Del(ctx, ks...).Err()
}
Expand Down Expand Up @@ -2195,7 +2234,6 @@ func (b *browserService) DeleteKeys(server string, db int, ks []any, serialNo st
cancelFunc()
})
total := len(ks)
var failed atomic.Int64
var canceled bool
var deletedKeys = make([]any, 0, total)
var mutex sync.Mutex
Expand All @@ -2210,9 +2248,7 @@ func (b *browserService) DeleteKeys(server string, db int, ks []any, serialNo st
}
cmders, delErr := pipe.Exec(ctx)
for j, cmder := range cmders {
if cmder.(*redis.IntCmd).Val() != 1 {
failed.Add(1)
} else {
if cmder.(*redis.IntCmd).Val() == 1 {
// save deleted key
mutex.Lock()
deletedKeys = append(deletedKeys, ks[i+j])
Expand All @@ -2239,13 +2275,13 @@ func (b *browserService) DeleteKeys(server string, db int, ks []any, serialNo st
cancelStopEvent()
resp.Success = true
resp.Data = struct {
Canceled bool `json:"canceled"`
Deleted any `json:"deleted"`
Failed int64 `json:"failed"`
Canceled bool `json:"canceled"`
Deleted any `json:"deleted"`
Failed int `json:"failed"`
}{
Canceled: canceled,
Deleted: deletedKeys,
Failed: failed.Load(),
Failed: len(ks) - len(deletedKeys),
}
return
}
Expand Down Expand Up @@ -2561,6 +2597,7 @@ func (b *browserService) GetSlowLogs(server string, num int64) (resp types.JSRes
resp.Msg = err.Error()
return
}
num = max(1, num)

client, ctx := item.client, item.ctx
var logs []redis.SlowLog
Expand Down
9 changes: 2 additions & 7 deletions backend/services/pubsub_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package services

import (
"context"
"errors"
"fmt"
"github.com/redis/go-redis/v9"
"github.com/wailsapp/wails/v2/pkg/runtime"
Expand All @@ -13,7 +12,7 @@ import (
)

type pubsubItem struct {
client *redis.Client
client redis.UniversalClient
pubsub *redis.PubSub
mutex sync.Mutex
closeCh chan struct{}
Expand Down Expand Up @@ -62,12 +61,8 @@ func (p *pubsubService) getItem(server string) (*pubsubItem, error) {
if uniClient, err = Connection().createRedisClient(conf.ConnectionConfig); err != nil {
return nil, err
}
var client *redis.Client
if client, ok = uniClient.(*redis.Client); !ok {
return nil, errors.New("create redis client fail")
}
item = &pubsubItem{
client: client,
client: uniClient,
}
p.items[server] = item
}
Expand Down
4 changes: 3 additions & 1 deletion backend/storage/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type PreferencesStorage struct {
}

func NewPreferences() *PreferencesStorage {
storage := NewLocalStore("preferences.yaml")
log.Printf("preferences path: %s\n", storage.ConfPath)
return &PreferencesStorage{
storage: NewLocalStore("preferences.yaml"),
storage: storage,
}
}

Expand Down
9 changes: 9 additions & 0 deletions backend/types/js_resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ type SetZSetParam struct {
RetFormat string `json:"retFormat,omitempty"`
RetDecode string `json:"retDecode,omitempty"`
}

type GetHashParam struct {
Server string `json:"server"`
DB int `json:"db"`
Key any `json:"key"`
Field string `json:"field,omitempty"`
Format string `json:"format,omitempty"`
Decode string `json:"decode,omitempty"`
}
14 changes: 3 additions & 11 deletions backend/utils/convert/json_convert.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package convutil

import (
"bytes"
"encoding/json"
"strings"
strutil "tinyrdm/backend/utils/string"
)

type JsonConvert struct{}
Expand All @@ -16,18 +15,11 @@ func (JsonConvert) Decode(str string) (string, bool) {
trimedStr := strings.TrimSpace(str)
if (strings.HasPrefix(trimedStr, "{") && strings.HasSuffix(trimedStr, "}")) ||
(strings.HasPrefix(trimedStr, "[") && strings.HasSuffix(trimedStr, "]")) {
var out bytes.Buffer
if err := json.Indent(&out, []byte(trimedStr), "", " "); err == nil {
return out.String(), true
}
return strutil.JSONBeautify(trimedStr, " "), true
}
return str, false
}

func (JsonConvert) Encode(str string) (string, bool) {
var dst bytes.Buffer
if err := json.Compact(&dst, []byte(str)); err != nil {
return str, false
}
return dst.String(), true
return strutil.JSONMinify(str), true
}
6 changes: 5 additions & 1 deletion backend/utils/convert/php_convert.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package convutil

import (
"os/exec"
)

type PhpConvert struct {
CmdConvert
}
Expand Down Expand Up @@ -47,7 +51,7 @@ func NewPhpConvert() *PhpConvert {
}

var err error
if _, err = runCommand(c.DecodePath, "-v"); err != nil {
if _, err = exec.LookPath(c.DecodePath); err != nil {
return nil
}

Expand Down
17 changes: 15 additions & 2 deletions backend/utils/convert/pickle_convert.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package convutil

import (
"os/exec"
"runtime"
)

type PickleConvert struct {
CmdConvert
}
Expand Down Expand Up @@ -40,13 +45,21 @@ func NewPickleConvert() *PickleConvert {
}
c.DecodePath, c.EncodePath = "python3", "python3"
var err error
if _, err = runCommand(c.DecodePath, "--version"); err != nil {
if _, err = exec.LookPath(c.DecodePath); err != nil {
c.DecodePath, c.EncodePath = "python", "python"
if _, err = runCommand(c.DecodePath, "--version"); err != nil {
if _, err = exec.LookPath(c.DecodePath); err != nil {
return nil
}
}
// check if pickle available
if runtime.GOOS == "darwin" {
// the xcode-select installation prompt may appear on macOS
// so check it manually in advance
if _, err = exec.LookPath("xcode-select"); err != nil {
return nil
}
}

if _, err = runCommand(c.DecodePath, "-c", "import pickle"); err != nil {
return nil
}
Expand Down
16 changes: 5 additions & 11 deletions backend/utils/convert/unicode_json_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package convutil

import (
"bytes"
"encoding/json"
"strconv"
"strings"
strutil "tinyrdm/backend/utils/string"
"unicode"
"unicode/utf16"
"unicode/utf8"
Expand All @@ -20,22 +20,16 @@ func (UnicodeJsonConvert) Decode(str string) (string, bool) {
trimedStr := strings.TrimSpace(str)
if (strings.HasPrefix(trimedStr, "{") && strings.HasSuffix(trimedStr, "}")) ||
(strings.HasPrefix(trimedStr, "[") && strings.HasSuffix(trimedStr, "]")) {
var out bytes.Buffer
if err := json.Indent(&out, []byte(trimedStr), "", " "); err == nil {
if quoteStr, ok := UnquoteUnicodeJson(out.Bytes()); ok {
return string(quoteStr), true
}
resultStr := strutil.JSONBeautify(trimedStr, " ")
if quoteStr, ok := UnquoteUnicodeJson([]byte(resultStr)); ok {
return string(quoteStr), true
}
}
return str, false
}

func (UnicodeJsonConvert) Encode(str string) (string, bool) {
var dst bytes.Buffer
if err := json.Compact(&dst, []byte(str)); err != nil {
return str, false
}
return dst.String(), true
return strutil.JSONMinify(str), true
}

func UnquoteUnicodeJson(s []byte) ([]byte, bool) {
Expand Down
Loading

0 comments on commit b472cb7

Please sign in to comment.