github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/api4/image.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package api4 5 6 import ( 7 "net/http" 8 "net/url" 9 10 "github.com/vnforks/kid/v5/model" 11 ) 12 13 func (api *API) InitImage() { 14 api.BaseRoutes.Image.Handle("", api.ApiSessionRequiredTrustRequester(getImage)).Methods("GET") 15 } 16 17 func getImage(c *Context, w http.ResponseWriter, r *http.Request) { 18 actualURL := r.URL.Query().Get("url") 19 parsedURL, err := url.Parse(actualURL) 20 if err != nil { 21 c.Err = model.NewAppError("getImage", "api.image.get.app_error", nil, err.Error(), http.StatusBadRequest) 22 return 23 } 24 25 // in case image proxy is enabled and we are fetching a remote image (NOT static or served by plugins), pass request to proxy 26 if *c.App.Config().ImageProxySettings.Enable && parsedURL.IsAbs() { 27 c.App.ImageProxy().GetImage(w, r, actualURL) 28 } else { 29 http.Redirect(w, r, actualURL, http.StatusFound) 30 } 31 }