Skip to content

Commit

Permalink
feat: batchExec
Browse files Browse the repository at this point in the history
  • Loading branch information
huaxiabuluo committed May 12, 2022
1 parent f4bbbf8 commit 9758ae4
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const publicConfig = {
path: path.join(__dirname, '../dist/'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[contenthash].js',
publicPath: '/assets/',
publicPath: '/',
},
module: {
rules: [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions server-v2/api/studio/internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions server-v2/api/studio/internal/logic/gateway/batchexecngqllogic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gateway

import (
"context"

"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/service"
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc"
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type BatchExecNGQLLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewBatchExecNGQLLogic(ctx context.Context, svcCtx *svc.ServiceContext) BatchExecNGQLLogic {
return BatchExecNGQLLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *BatchExecNGQLLogic) BatchExecNGQL(req types.BatchExecNGQLParams) (*types.AnyResponse, error) {
return service.NewGatewayService(l.ctx, l.svcCtx).BatchExecNGQL(&req)
}
40 changes: 40 additions & 0 deletions server-v2/api/studio/internal/service/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"strings"

"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/gateway/dao"
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc"
Expand All @@ -16,6 +17,7 @@ var _ GatewayService = (*gatewayService)(nil)
type (
GatewayService interface {
ExecNGQL(request *types.ExecNGQLParams) (*types.AnyResponse, error)
BatchExecNGQL(request *types.BatchExecNGQLParams) (*types.AnyResponse, error)
ConnectDB(request *types.ConnectDBParams) (*types.ConnectDBResult, error)
DisconnectDB(request *types.DisconnectDBParams) (*types.AnyResponse, error)
}
Expand Down Expand Up @@ -55,3 +57,41 @@ func (s *gatewayService) ExecNGQL(request *types.ExecNGQLParams) (*types.AnyResp
}
return &types.AnyResponse{Data: execute}, nil
}

func (s *gatewayService) BatchExecNGQL(request *types.BatchExecNGQLParams) (*types.AnyResponse, error) {
data := make([]map[string]interface{}, 0)

NSID := request.NSID
gqls := request.Gqls
paramList := request.ParamList

for _, gql := range gqls {
execute, _, err := dao.Execute(NSID, gql, make([]string, 0))
gqlRes := make(map[string]interface{})
gqlRes["gql"] = gql
if err != nil {
gqlRes["message"] = err.Error()
gqlRes["code"] = -1
} else {
gqlRes["code"] = 0
}
gqlRes["data"] = execute
data = append(data, gqlRes)
}

if len(paramList) > 0 {
execute, _, err := dao.Execute(NSID, "", paramList)
gqlRes := make(map[string]interface{})
gqlRes["gql"] = strings.Join(paramList, "; ")
if err != nil {
gqlRes["message"] = err.Error()
gqlRes["code"] = -1
} else {
gqlRes["code"] = 0
}
gqlRes["data"] = execute
data = append(data, gqlRes)
}

return &types.AnyResponse{Data: data}, nil
}
6 changes: 6 additions & 0 deletions server-v2/api/studio/internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions server-v2/api/studio/pkg/auth/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type (
}
)

var (
tokenName = "explorer_token"
nsidName = "explorer_nsid"
)

func CreateToken(authData *AuthData, config *config.Config) (string, error) {
now := time.Now()
expiresAt := now.Add(time.Duration(config.Auth.AccessExpire) * time.Second).Unix()
Expand Down Expand Up @@ -136,14 +141,14 @@ func AuthMiddlewareWithCtx(svcCtx *svc.ServiceContext) rest.Middleware {
}

token := http.Cookie{
Name: "token",
Name: tokenName,
Value: tokenString,
Path: "/",
HttpOnly: true,
MaxAge: int(configAuth.AccessExpire),
}
NSID := http.Cookie{
Name: "NSID",
Name: nsidName,
Value: clientInfo.ClientID,
Path: "/",
HttpOnly: true,
Expand All @@ -159,20 +164,20 @@ func AuthMiddlewareWithCtx(svcCtx *svc.ServiceContext) rest.Middleware {
return
}

NSIDCookie, NSIDErr := r.Cookie("NSID")
NSIDCookie, NSIDErr := r.Cookie(nsidName)
if NSIDErr == nil {
// Add NSID to request query
utils.AddQueryParams(r, map[string]string{"NSID": NSIDCookie.Value})
}

if strings.HasSuffix(r.URL.Path, "/disconnect") {
w.Header().Set("Set-Cookie", utils.DisabledCookie("token").String())
w.Header().Add("Set-Cookie", utils.DisabledCookie("NSID").String())
w.Header().Set("Set-Cookie", utils.DisabledCookie(tokenName).String())
w.Header().Add("Set-Cookie", utils.DisabledCookie(nsidName).String())
next(w, r)
return
}

tokenCookie, tokenErr := r.Cookie("token")
tokenCookie, tokenErr := r.Cookie(tokenName)
if NSIDErr != nil || tokenErr != nil {
if NSIDErr != nil {
svcCtx.ResponseHandler.Handle(w, r, nil, ecode.WithSessionMessage(NSIDErr))
Expand Down
10 changes: 9 additions & 1 deletion server-v2/api/studio/restapi/gateway.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ type (
ParamList []string `json:"paramList,optional"`
NSID string `form:"NSID"`
}
BatchExecNGQLParams {
Gqls []string `json:"gqls"`
ParamList []string `json:"paramList,optional"`
NSID string `form:"NSID"`
}
ConnectDBParams {
Address string `json:"address"`
Port int `json:"port"`
Expand All @@ -18,7 +23,6 @@ type (
DisconnectDBParams {
NSID string `form:"NSID,optional"`
}

AnyResponse {
Data interface{} `json:"data"`
}
Expand All @@ -33,6 +37,10 @@ service studio-api {
@doc "Exec NGQL"
@handler ExecNGQL
post /exec(ExecNGQLParams) returns (AnyResponse)

@doc "BatchExec NGQL"
@handler BatchExecNGQL
post /batchExec(BatchExecNGQLParams) returns (AnyResponse)
}

@server(
Expand Down

0 comments on commit 9758ae4

Please sign in to comment.