feat(backend): added new fields to mobile start request

This commit is contained in:
Alexander 2024-03-25 09:14:00 +01:00
parent 80f0005362
commit 8c84fd6550
2 changed files with 16 additions and 6 deletions

View file

@ -28,7 +28,7 @@ func (e *Router) startSessionHandlerIOS(w http.ResponseWriter, r *http.Request)
body := http.MaxBytesReader(w, r.Body, e.cfg.JsonSizeLimit)
defer body.Close()
req := &StartIOSSessionRequest{}
req := &StartMobileSessionRequest{}
if err := json.NewDecoder(body).Decode(req); err != nil {
e.ResponseWithError(r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, 0)
return
@ -105,18 +105,24 @@ func (e *Router) startSessionHandlerIOS(w http.ResponseWriter, r *http.Request)
r = r.WithContext(context.WithValue(r.Context(), "sessionID", fmt.Sprintf("%d", sessionID)))
geoInfo := e.ExtractGeoData(r)
platform, os, screen := "ios", "IOS", ""
if req.Platform != "" && req.Platform != "ios" {
platform = req.Platform
os = "Android"
screen = fmt.Sprintf("%d:%d", req.Width, req.Height)
}
if !req.DoNotRecord {
if err := e.services.Sessions.Add(&sessions.Session{
SessionID: sessionID,
Platform: "ios",
Platform: platform,
Timestamp: req.Timestamp,
Timezone: req.Timezone,
ProjectID: p.ProjectID,
TrackerVersion: req.TrackerVersion,
RevID: req.RevID,
UserUUID: userUUID,
UserOS: "IOS",
UserOS: os,
UserOSVersion: req.UserOSVersion,
UserDevice: ios.MapIOSDevice(req.UserDevice),
UserDeviceType: ios.GetIOSDeviceType(req.UserDevice),
@ -125,6 +131,7 @@ func (e *Router) startSessionHandlerIOS(w http.ResponseWriter, r *http.Request)
UserCity: geoInfo.City,
UserDeviceMemorySize: req.DeviceMemory,
UserDeviceHeapSize: req.DeviceMemory,
UserBrowser: screen,
}); err != nil {
e.log.Warn(r.Context(), "failed to add mobile session to DB: %s", err)
}
@ -148,7 +155,7 @@ func (e *Router) startSessionHandlerIOS(w http.ResponseWriter, r *http.Request)
}
}
e.ResponseWithJSON(r.Context(), w, &StartIOSSessionResponse{
e.ResponseWithJSON(r.Context(), w, &StartMobileSessionResponse{
Token: e.services.Tokenizer.Compose(*tokenData),
UserUUID: userUUID,
SessionID: strconv.FormatUint(tokenData.ID, 10),

View file

@ -46,7 +46,7 @@ type NotStartedRequest struct {
DoNotTrack bool `json:"DoNotTrack"`
}
type StartIOSSessionRequest struct {
type StartMobileSessionRequest struct {
Token string `json:"token"`
ProjectKey *string `json:"projectKey"`
TrackerVersion string `json:"trackerVersion"`
@ -59,9 +59,12 @@ type StartIOSSessionRequest struct {
DeviceMemory uint64 `json:"deviceMemory"`
DoNotRecord bool `json:"doNotRecord"` // start record session or not
Condition string `json:"condition"` // condition for start record session
Platform string `json:"platform"`
Width int `json:"width"`
Height int `json:"height"`
}
type StartIOSSessionResponse struct {
type StartMobileSessionResponse struct {
Token string `json:"token"`
ImagesHashList []string `json:"imagesHashList"`
UserUUID string `json:"userUUID"`