diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-02-24 06:15:13 -0500 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-02-24 11:15:13 +0000 |
commit | ace228c4e52bd25dca24d1a5b35eff97740e5ea2 (patch) | |
tree | ddf37fe056dc62ad1e70009f538a36961d666b3f /api4/post.go | |
parent | 80273d02347a3ac35ba2566151b53e8a420e2d0a (diff) | |
download | chat-ace228c4e52bd25dca24d1a5b35eff97740e5ea2.tar.gz chat-ace228c4e52bd25dca24d1a5b35eff97740e5ea2.tar.bz2 chat-ace228c4e52bd25dca24d1a5b35eff97740e5ea2.zip |
Implement GET /posts/{post_id}/files/info endpoint for APIv4 (#5519)
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/api4/post.go b/api4/post.go index 7290ce8ef..6a8b1bff2 100644 --- a/api4/post.go +++ b/api4/post.go @@ -20,6 +20,7 @@ func InitPost() { BaseRoutes.Post.Handle("", ApiSessionRequired(getPost)).Methods("GET") BaseRoutes.Post.Handle("", ApiSessionRequired(deletePost)).Methods("DELETE") BaseRoutes.Post.Handle("/thread", ApiSessionRequired(getPostThread)).Methods("GET") + BaseRoutes.Post.Handle("/files/info", ApiSessionRequired(getFileInfosForPost)).Methods("GET") BaseRoutes.PostsForChannel.Handle("", ApiSessionRequired(getPostsForChannel)).Methods("GET") BaseRoutes.Team.Handle("/posts/search", ApiSessionRequired(searchPosts)).Methods("POST") @@ -174,3 +175,26 @@ 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())) } + +func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequirePostId() + if c.Err != nil { + return + } + + if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return + } + + if infos, err := app.GetFileInfosForPost(c.Params.PostId, false); err != nil { + c.Err = err + return + } else if HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) { + return + } else { + w.Header().Set("Cache-Control", "max-age=2592000, public") + w.Header().Set(model.HEADER_ETAG_SERVER, model.GetEtagForFileInfos(infos)) + w.Write([]byte(model.FileInfosToJson(infos))) + } +} |