summaryrefslogtreecommitdiffstats
path: root/api4/image.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2018-02-09 13:56:11 -0600
committerChristopher Brown <ccbrown112@gmail.com>2018-02-09 13:59:17 -0600
commita4e9499714999d58f26c712df02c014f1facccf7 (patch)
tree0d7031485ce74b502746d5a9fe2f65ca2c82d38e /api4/image.go
parent9bf23ece6c247fb04a57127260de4608c433daa5 (diff)
downloadchat-a4e9499714999d58f26c712df02c014f1facccf7.tar.gz
chat-a4e9499714999d58f26c712df02c014f1facccf7.tar.bz2
chat-a4e9499714999d58f26c712df02c014f1facccf7.zip
Add /v4/image api (#8230)
* add image api * i suppose i should add a test... * only redirect to image proxy
Diffstat (limited to 'api4/image.go')
-rw-r--r--api4/image.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/api4/image.go b/api4/image.go
new file mode 100644
index 000000000..4589de204
--- /dev/null
+++ b/api4/image.go
@@ -0,0 +1,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)
+ }
+}