Files
mattermost/api4/image.go
Chris 0daac7e4fc Add /v4/image api (#8230)
* add image api

* i suppose i should add a test...

* only redirect to image proxy
2018-02-09 11:56:11 -08:00

23 lines
641 B
Go

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api4
import (
"net/http"
)
func (api *API) InitImage() {
api.BaseRoutes.Image.Handle("", api.ApiSessionRequiredTrustRequester(getImage)).Methods("GET")
}
func getImage(c *Context, w http.ResponseWriter, r *http.Request) {
// Only redirect to our image proxy if one is enabled. Arbitrary redirects are not allowed for
// security reasons.
if transform := c.App.ImageProxyAdder(); transform != nil {
http.Redirect(w, r, transform(r.URL.Query().Get("url")), http.StatusFound)
} else {
http.NotFound(w, r)
}
}