summaryrefslogtreecommitdiffstats
path: root/api4/image.go
blob: 4589de20451266478fc327a994e905ac67ca788a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 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)
	}
}