APIv4: GET /files/{file_id}/info (#5591)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
8b59a2a291
Коммит
3cbe05e0f4
22
api4/file.go
22
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)))
|
||||
|
||||
Ссылка в новой задаче
Block a user