коммит произвёл
Joram Wilander
родитель
8c5744492f
Коммит
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) {
|
func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
params := mux.Vars(r)
|
params := mux.Vars(r)
|
||||||
id := params["user_id"]
|
id := params["user_id"]
|
||||||
|
readFailed := false
|
||||||
|
|
||||||
if result := <-Srv.Store.User().Get(id); result.Err != nil {
|
if result := <-Srv.Store.User().Get(id); result.Err != nil {
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
@@ -1268,15 +1269,18 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
path := "users/" + id + "/profile.png"
|
path := "users/" + id + "/profile.png"
|
||||||
|
|
||||||
if data, err := ReadFile(path); err != nil {
|
if data, err := ReadFile(path); err != nil {
|
||||||
|
readFailed = true
|
||||||
|
|
||||||
if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil {
|
if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := WriteFile(img, path); err != nil {
|
if result.Data.(*model.User).LastPictureUpdate == 0 {
|
||||||
c.Err = err
|
if err := WriteFile(img, path); err != nil {
|
||||||
return
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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
|
w.Header().Set("Cache-Control", "max-age=300, public") // 5 mins
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs
|
w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user