mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
committed by
Joram Wilander
parent
8c5744492f
commit
2c09582d89
12
api/user.go
12
api/user.go
@@ -1251,6 +1251,7 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError
|
||||
func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
id := params["user_id"]
|
||||
readFailed := false
|
||||
|
||||
if result := <-Srv.Store.User().Get(id); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
@@ -1268,15 +1269,18 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
path := "users/" + id + "/profile.png"
|
||||
|
||||
if data, err := ReadFile(path); err != nil {
|
||||
readFailed = true
|
||||
|
||||
if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if err := WriteFile(img, path); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
if result.Data.(*model.User).LastPictureUpdate == 0 {
|
||||
if err := WriteFile(img, path); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -1284,7 +1288,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if c.Session.UserId == id {
|
||||
if c.Session.UserId == id || readFailed {
|
||||
w.Header().Set("Cache-Control", "max-age=300, public") // 5 mins
|
||||
} else {
|
||||
w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs
|
||||
|
||||
Reference in New Issue
Block a user