From 3cbe05e0f48673adf0306cc1fcb97eb224c375ac Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Tue, 14 Mar 2017 05:34:43 +0900 Subject: APIv4: GET /files/{file_id}/info (#5591) --- api4/file.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'api4/file.go') 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))) -- cgit v1.2.3-1-g7c22