From 599991ea731953f772824ce3ed1e591246aa004f Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 Jan 2018 15:32:50 -0600 Subject: PLT-3383: image proxy support (#7991) * image proxy support * go vet fix, remove mistakenly added coverage file * fix test compile error * add validation to config settings and documentation to model functions * add message_source field to post --- api4/channel.go | 2 +- api4/post.go | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'api4') diff --git a/api4/channel.go b/api4/channel.go index f8a069ea0..9801c9dc0 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -386,7 +386,7 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) { return } else { w.Header().Set(model.HEADER_ETAG_SERVER, posts.Etag()) - w.Write([]byte(posts.ToJson())) + w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(posts).ToJson())) } } diff --git a/api4/post.go b/api4/post.go index 7a365845f..80088d9ef 100644 --- a/api4/post.go +++ b/api4/post.go @@ -56,7 +56,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { post.CreateAt = 0 } - rp, err := c.App.CreatePostAsUser(post) + rp, err := c.App.CreatePostAsUser(c.App.PostWithProxyRemovedFromImageURLs(post)) if err != nil { c.Err = err return @@ -66,7 +66,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { c.App.UpdateLastActivityAtIfNeeded(c.Session) w.WriteHeader(http.StatusCreated) - w.Write([]byte(rp.ToJson())) + w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rp).ToJson())) } func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { @@ -135,7 +135,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { if len(etag) > 0 { w.Header().Set(model.HEADER_ETAG_SERVER, etag) } - w.Write([]byte(list.ToJson())) + w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(list).ToJson())) } func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request) { @@ -168,7 +168,7 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request) return } - w.Write([]byte(posts.ToJson())) + w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(posts).ToJson())) } func getPost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -206,7 +206,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) { return } else { w.Header().Set(model.HEADER_ETAG_SERVER, post.Etag()) - w.Write([]byte(post.ToJson())) + w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(post).ToJson())) } } @@ -272,7 +272,7 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) { return } else { w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag()) - w.Write([]byte(list.ToJson())) + w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(list).ToJson())) } } @@ -313,7 +313,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { } w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - w.Write([]byte(posts.ToJson())) + w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(posts).ToJson())) } func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -341,13 +341,13 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { post.Id = c.Params.PostId - rpost, err := c.App.UpdatePost(post, false) + rpost, err := c.App.UpdatePost(c.App.PostWithProxyRemovedFromImageURLs(post), false) if err != nil { c.Err = err return } - w.Write([]byte(rpost.ToJson())) + w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rpost).ToJson())) } func patchPost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -373,13 +373,13 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - patchedPost, err := c.App.PatchPost(c.Params.PostId, post) + patchedPost, err := c.App.PatchPost(c.Params.PostId, c.App.PostPatchWithProxyRemovedFromImageURLs(post)) if err != nil { c.Err = err return } - w.Write([]byte(patchedPost.ToJson())) + w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(patchedPost).ToJson())) } func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinned bool) { -- cgit v1.2.3-1-g7c22