From a4a5ce649874884cd9ad7ec100d9040068c42975 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 16 Apr 2025 10:14:29 +0200 Subject: [PATCH] feat(assist-api): ignore request's body for isLive and getByID --- ee/backend/pkg/assist/api/handlers.go | 32 ++------------------- ee/backend/pkg/assist/api/model.go | 1 - ee/backend/pkg/assist/service/assist.go | 38 +++---------------------- ee/backend/pkg/assist/service/model.go | 27 ++++++++++++++++++ 4 files changed, 33 insertions(+), 65 deletions(-) delete mode 100644 ee/backend/pkg/assist/api/model.go create mode 100644 ee/backend/pkg/assist/service/model.go diff --git a/ee/backend/pkg/assist/api/handlers.go b/ee/backend/pkg/assist/api/handlers.go index 890c2c8bc..60c6975dc 100644 --- a/ee/backend/pkg/assist/api/handlers.go +++ b/ee/backend/pkg/assist/api/handlers.go @@ -101,7 +101,6 @@ func (e *handlersImpl) autocomplete(w http.ResponseWriter, r *http.Request) { e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize) return } - e.log.Debug(context.Background(), "autocomplete request, projectKey: %s, query: %v, response: %v", projectKey, query, resp) response := map[string]interface{}{ "data": resp, } @@ -122,25 +121,12 @@ func (e *handlersImpl) socketsListByProject(w http.ResponseWriter, r *http.Reque e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize) return } - bodyBytes, err := api.ReadBody(e.log, w, r, e.jsonSizeLimit) - if err != nil { - e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusRequestEntityTooLarge, err, startTime, r.URL.Path, bodySize) - return - } - e.log.Debug(context.Background(), "bodyBytes: %s", bodyBytes) - bodySize = len(bodyBytes) - req := &service.Request{} - if err := json.Unmarshal(bodyBytes, req); err != nil { - e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize) - return - } - resp, err := e.assist.GetByID(projectKey, sessionID, req) + resp, err := e.assist.GetByID(projectKey, sessionID) if err != nil { e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize) return } - e.log.Debug(context.Background(), "socketsListByProject request, projectKey: %s, sessionID: %s, req: %v, response: %v", projectKey, sessionID, req, resp) response := map[string]interface{}{ "data": resp, } @@ -174,7 +160,6 @@ func (e *handlersImpl) socketsLiveByProject(w http.ResponseWriter, r *http.Reque e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize) return } - e.log.Debug(context.Background(), "socketsLiveByProject request, filters: %v, projectKey: %s, response: %v", req, projectKey, resp) response := map[string]interface{}{ "data": resp, } @@ -195,25 +180,12 @@ func (e *handlersImpl) socketsLiveBySession(w http.ResponseWriter, r *http.Reque e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize) return } - bodyBytes, err := api.ReadBody(e.log, w, r, e.jsonSizeLimit) - if err != nil { - e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusRequestEntityTooLarge, err, startTime, r.URL.Path, bodySize) - return - } - e.log.Debug(context.Background(), "bodyBytes: %s", bodyBytes) - bodySize = len(bodyBytes) - req := &service.Request{} - if err := json.Unmarshal(bodyBytes, req); err != nil { - e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize) - return - } - resp, err := e.assist.GetByID(projectKey, sessionID, req) + resp, err := e.assist.GetByID(projectKey, sessionID) if err != nil { e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize) return } - e.log.Debug(context.Background(), "socketsLiveBySession request, projectKey: %s, sessionID: %s, req: %v, response: %v", projectKey, sessionID, req, resp) response := map[string]interface{}{ "data": resp, } diff --git a/ee/backend/pkg/assist/api/model.go b/ee/backend/pkg/assist/api/model.go deleted file mode 100644 index 778f64ec1..000000000 --- a/ee/backend/pkg/assist/api/model.go +++ /dev/null @@ -1 +0,0 @@ -package api diff --git a/ee/backend/pkg/assist/service/assist.go b/ee/backend/pkg/assist/service/assist.go index da4bc1bd1..684574ae8 100644 --- a/ee/backend/pkg/assist/service/assist.go +++ b/ee/backend/pkg/assist/service/assist.go @@ -10,32 +10,6 @@ import ( "openreplay/backend/pkg/sessionmanager" ) -type Query struct { - Key string - Value string -} - -type Filter struct { - Value []string `json:"values"` - Operator string `json:"operator"` // is|contains -} - -type Pagination struct { - Limit int `json:"limit"` - Page int `json:"page"` -} - -type Sort struct { - Key string `json:"key"` // useless - Order string `json:"order"` // [ASC|DESC] -} - -type Request struct { - Filters map[string]Filter `json:"filter"` - Pagination Pagination `json:"pagination"` - Sort Sort `json:"sort"` -} - type assistImpl struct { log logger.Logger pgconn pool.Pool @@ -45,9 +19,9 @@ type assistImpl struct { type Assist interface { Autocomplete(projectKey string, query *Query) (interface{}, error) - IsLive(projectKey, sessionID string, filters *Request) (bool, error) + IsLive(projectKey, sessionID string) (bool, error) GetAll(projectKey string, filters *Request) (interface{}, error) - GetByID(projectKey, sessionID string, filters *Request) (interface{}, error) + GetByID(projectKey, sessionID string) (interface{}, error) } func NewAssist(log logger.Logger, pgconn pool.Pool, projects projects.Projects, sessions sessionmanager.SessionManager) Assist { @@ -77,14 +51,12 @@ func (a *assistImpl) Autocomplete(projectKey string, query *Query) (interface{}, return a.sessions.Autocomplete(strconv.Itoa(int(project.ProjectID)), sessionmanager.FilterType(query.Key), query.Value) } -func (a *assistImpl) IsLive(projectKey, sessionID string, filters *Request) (bool, error) { +func (a *assistImpl) IsLive(projectKey, sessionID string) (bool, error) { switch { case projectKey == "": return false, fmt.Errorf("project key is required") case sessionID == "": return false, fmt.Errorf("session ID is required") - case filters == nil: - return false, fmt.Errorf("filters are required") } project, err := a.projects.GetProjectByKey(projectKey) if err != nil { @@ -132,14 +104,12 @@ func (a *assistImpl) GetAll(projectKey string, request *Request) (interface{}, e return resp, nil } -func (a *assistImpl) GetByID(projectKey, sessionID string, filters *Request) (interface{}, error) { +func (a *assistImpl) GetByID(projectKey, sessionID string) (interface{}, error) { switch { case projectKey == "": return nil, fmt.Errorf("project key is required") case sessionID == "": return nil, fmt.Errorf("session ID is required") - case filters == nil: - return nil, fmt.Errorf("filters are required") } project, err := a.projects.GetProjectByKey(projectKey) if err != nil { diff --git a/ee/backend/pkg/assist/service/model.go b/ee/backend/pkg/assist/service/model.go new file mode 100644 index 000000000..dfd1b017b --- /dev/null +++ b/ee/backend/pkg/assist/service/model.go @@ -0,0 +1,27 @@ +package service + +type Query struct { + Key string + Value string +} + +type Filter struct { + Value []string `json:"values"` + Operator string `json:"operator"` // is|contains +} + +type Pagination struct { + Limit int `json:"limit"` + Page int `json:"page"` +} + +type Sort struct { + Key string `json:"key"` // useless + Order string `json:"order"` // [ASC|DESC] +} + +type Request struct { + Filters map[string]Filter `json:"filter"` + Pagination Pagination `json:"pagination"` + Sort Sort `json:"sort"` +}