Browse Source

增加更新域meta

xuzhiheng 4 năm trước cách đây
mục cha
commit
6a3c8f3ccf

+ 3 - 0
rpc/internal/logic/deletedomainlogic.go

@@ -3,6 +3,8 @@ package logic
 import (
 	"context"
 
+	"app.yhyue.com/moapp/jyfs/rpc/internal/redis"
+
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
 
@@ -29,6 +31,7 @@ func (l *DeleteDomainLogic) DeleteDomain(in *filesystem.DomainReq) (*filesystem.
 	if err != nil {
 		return &filesystem.DomainResp{State: false}, nil
 	} else {
+		redis.Del("jyfs", "jyfs_"+in.Name)
 		return &filesystem.DomainResp{State: true}, nil
 	}
 }

+ 11 - 1
rpc/internal/logic/updatedomainmetalogic.go

@@ -2,6 +2,10 @@ package logic
 
 import (
 	"context"
+	"errors"
+	"strings"
+
+	"app.yhyue.com/moapp/jyfs/rpc/internal/redis"
 
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
@@ -26,5 +30,11 @@ func NewUpdateDomainMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 // 更新域
 func (l *UpdateDomainMetaLogic) UpdateDomainMeta(in *filesystem.DomainReq) (*filesystem.DomainResp, error) {
 	// todo: add your logic here and delete this line
-	return &filesystem.DomainResp{}, nil
+	meta := redis.GetStr("jyfs", "jyfs_"+in.Name)
+	if meta != "" {
+		redis.Put("jyfs", "jyfs_"+in.Name, strings.Join(in.MetaFields, ","), -1)
+	} else {
+		return &filesystem.DomainResp{State: false}, errors.New("域元信息为空")
+	}
+	return &filesystem.DomainResp{State: true}, nil
 }

+ 16 - 5
rpc/test/jyfs_rpc_test.go

@@ -6,10 +6,11 @@ import (
 	"testing"
 	"time"
 
+	"os"
+
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/config"
-
 	"github.com/tal-tech/go-zero/core/conf"
 	"github.com/tal-tech/go-zero/zrpc"
 )
@@ -40,6 +41,16 @@ func Test_DeleteDomain(t *testing.T) {
 	log.Println("req ", res)
 }
 
+// 更新域
+func Test_UpdateDomainMeta(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{"docName", "docSuffix", "docSize", "docPage"}}
+	res, err := FileSystem.UpdateDomainMeta(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
 // 删除文件
 func Test_DeleteFile(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
@@ -76,21 +87,21 @@ func Test_SaveFile(t *testing.T) {
 	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
 	file, err := os.Open("./111.txt")
 	if err != nil {
-		return nil, err
+		return
 	}
 	defer file.Close()
 	// FileInfo:
 	stats, err := file.Stat()
 	if err != nil {
-		return nil, err
+		return
 	}
 	// []byte
 	data := make([]byte, stats.Size())
 	count, err := file.Read(data)
 	if err != nil {
-		return nil, err
+		return
 	}
-	fmt.Println(count)
+	log.Println(count)
 	req := &filesystem.SaveFileReq{
 		Domain:         "xzh",
 		FileId:         "111.txt",