diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-03-14 05:34:43 +0900 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-03-13 16:34:43 -0400 |
commit | 3cbe05e0f48673adf0306cc1fcb97eb224c375ac (patch) | |
tree | c8953e75037452a78d75bbe832cf0f3b467d3470 /api4/file.go | |
parent | 8b59a2a2914d7ac0b9f318e6d3208e31fa9dd88e (diff) | |
download | chat-3cbe05e0f48673adf0306cc1fcb97eb224c375ac.tar.gz chat-3cbe05e0f48673adf0306cc1fcb97eb224c375ac.tar.bz2 chat-3cbe05e0f48673adf0306cc1fcb97eb224c375ac.zip |
APIv4: GET /files/{file_id}/info (#5591)
Diffstat (limited to 'api4/file.go')
-rw-r--r-- | api4/file.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/api4/file.go b/api4/file.go index fa414faa3..d3c7f7a7f 100644 --- a/api4/file.go +++ b/api4/file.go @@ -26,6 +26,7 @@ func InitFile() { BaseRoutes.File.Handle("/thumbnail", ApiSessionRequired(getFileThumbnail)).Methods("GET") BaseRoutes.File.Handle("/link", ApiSessionRequired(getFileLink)).Methods("GET") BaseRoutes.File.Handle("/preview", ApiSessionRequired(getFilePreview)).Methods("GET") + BaseRoutes.File.Handle("/info", ApiSessionRequired(getFileInfo)).Methods("GET") } @@ -194,6 +195,27 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) { } } +func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireFileId() + if c.Err != nil { + return + } + + info, err := app.GetFileInfo(c.Params.FileId) + if err != nil { + c.Err = err + return + } + + if info.CreatorId != c.Session.UserId && !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return + } + + w.Header().Set("Cache-Control", "max-age=2592000, public") + w.Write([]byte(info.ToJson())) +} + func writeFileResponse(filename string, contentType string, bytes []byte, w http.ResponseWriter, r *http.Request) *model.AppError { w.Header().Set("Cache-Control", "max-age=2592000, public") w.Header().Set("Content-Length", strconv.Itoa(len(bytes))) |