summaryrefslogtreecommitdiffstats
path: root/api4/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'api4/file.go')
-rw-r--r--api4/file.go22
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)))