func (wh *webSocketHandler) ServeWebSocket(conn *WebConn, r *model.WebSocketRequest) { l4g.Debug("/api/v3/users/websocket:%s", r.Action) r.Session = *GetSession(conn.SessionToken) r.T = conn.T r.Locale = conn.Locale var data map[string]interface{} var err *model.AppError if data, err = wh.handlerFunc(r); err != nil { l4g.Error(utils.T("api.web_socket_handler.log.error"), "/api/v3/users/websocket", r.Action, r.Seq, r.Session.UserId, err.SystemMessage(utils.T), err.DetailedError) err.DetailedError = "" errResp := model.NewWebSocketError(r.Seq, err) errResp.DoPreComputeJson() conn.Send <- errResp return } resp := model.NewWebSocketResponse(model.STATUS_OK, r.Seq, data) resp.DoPreComputeJson() conn.Send <- resp }
func (wr *WebSocketRouter) ReturnWebSocketError(conn *WebConn, r *model.WebSocketRequest, err *model.AppError) { l4g.Error(utils.T("api.web_socket_router.log.error"), r.Seq, conn.UserId, err.SystemMessage(utils.T), err.DetailedError) err.DetailedError = "" errorResp := model.NewWebSocketError(r.Seq, err) conn.Send <- errorResp }
func (c *Context) LogError(err *model.AppError) { // filter out endless reconnects if c.Path == "/api/v3/users/websocket" && err.StatusCode == 401 || err.Id == "web.check_browser_compatibility.app_error" { c.LogDebug(err) } else { l4g.Error(utils.T("api.context.log.error"), c.Path, err.Where, err.StatusCode, c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.T), err.DetailedError) } }
func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["id"] if result := <-Srv.Store.User().Get(id); result.Err != nil { c.Err = result.Err return } else { var img []byte var err *model.AppError if !utils.IsS3Configured() { img, err = createProfileImage(result.Data.(*model.User).Username, id) if err != nil { c.Err = err return } } else { var auth aws.Auth auth.AccessKey = utils.Cfg.AWSSettings.S3AccessKeyId auth.SecretKey = utils.Cfg.AWSSettings.S3SecretAccessKey s := s3.New(auth, aws.Regions[utils.Cfg.AWSSettings.S3Region]) bucket := s.Bucket(utils.Cfg.AWSSettings.S3Bucket) path := "teams/" + c.Session.TeamId + "/users/" + id + "/profile.png" if data, getErr := bucket.Get(path); getErr != nil { img, err = createProfileImage(result.Data.(*model.User).Username, id) if err != nil { c.Err = err return } options := s3.Options{} if err := bucket.Put(path, img, "image", s3.Private, options); err != nil { c.Err = model.NewAppError("getImage", "Couldn't upload default profile image", err.Error()) return } } else { img = data } } if c.Session.UserId == id { w.Header().Set("Cache-Control", "max-age=300, public") // 5 mins } else { w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs } w.Write(img) } }
func (me *TestHelper) CreateTeam() *model.Team { id := model.NewId() team := &model.Team{ DisplayName: "dn_" + id, Name: "name" + id, Email: "success+" + id + "@simulator.amazonses.com", Type: model.TEAM_OPEN, } utils.DisableDebugLogForTest() var err *model.AppError if team, err = CreateTeam(team); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return team }
func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post { id := model.NewId() post := &model.Post{ UserId: me.BasicUser.Id, ChannelId: channel.Id, Message: "message_" + id, } utils.DisableDebugLogForTest() var err *model.AppError if post, err = CreatePost(post, channel.TeamId, false); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return post }
func (me *TestHelper) CreateUser() *model.User { id := model.NewId() user := &model.User{ Email: "success+" + id + "@simulator.amazonses.com", Username: "******" + id, Nickname: "nn_" + id, Password: "******", EmailVerified: true, } utils.DisableDebugLogForTest() var err *model.AppError if user, err = CreateUser(user); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return user }
func (me *TestHelper) createChannel(team *model.Team, channelType string) *model.Channel { id := model.NewId() channel := &model.Channel{ DisplayName: "dn_" + id, Name: "name_" + id, Type: channelType, TeamId: team.Id, CreatorId: me.BasicUser.Id, } utils.DisableDebugLogForTest() var err *model.AppError if channel, err = CreateChannel(channel, true); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return channel }
func (c *Context) LogDebug(err *model.AppError) { l4g.Debug(utils.T("api.context.log.error"), c.Path, err.Where, err.StatusCode, c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.T), err.DetailedError) }