[MM-44765] Add API method for getting post's information from permalink (#21518)

* add api for getting post's information

* add information about current user state

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Konstantinos Pittas
2022-12-05 16:04:44 +02:00
коммит произвёл GitHub
родитель 0c64252c9f
Коммит 3059abdd88
7 изменённых файлов: 398 добавлений и 0 удалений

Просмотреть файл

@@ -23,6 +23,7 @@ func (api *API) InitPost() {
api.BaseRoutes.Posts.Handle("/ids", api.APISessionRequired(getPostsByIds)).Methods("POST")
api.BaseRoutes.Posts.Handle("/ephemeral", api.APISessionRequired(createEphemeralPost)).Methods("POST")
api.BaseRoutes.Post.Handle("/thread", api.APISessionRequired(getPostThread)).Methods("GET")
api.BaseRoutes.Post.Handle("/info", api.APISessionRequired(getPostInfo)).Methods("GET")
api.BaseRoutes.Post.Handle("/files/info", api.APISessionRequired(getFileInfosForPost)).Methods("GET")
api.BaseRoutes.PostsForChannel.Handle("", api.APISessionRequired(getPostsForChannel)).Methods("GET")
api.BaseRoutes.PostsForUser.Handle("/flagged", api.APISessionRequired(getFlaggedPostsForUser)).Methods("GET")
@@ -1055,3 +1056,24 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set(model.HeaderEtagServer, model.GetEtagForFileInfos(infos))
w.Write(js)
}
func getPostInfo(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequirePostId()
if c.Err != nil {
return
}
info, appErr := c.App.GetPostInfo(c.AppContext, c.Params.PostId)
if appErr != nil {
c.Err = appErr
return
}
js, err := json.Marshal(info)
if err != nil {
c.Err = model.NewAppError("getPostInfo", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return
}
w.Write(js)
}