Implementing Permalinks and jumping to post from search. Performance
improvements.
Этот коммит содержится в:
36
api/post.go
36
api/post.go
@@ -23,6 +23,7 @@ func InitPost(r *mux.Router) {
|
||||
l4g.Debug("Initializing post api routes")
|
||||
|
||||
r.Handle("/posts/search", ApiUserRequired(searchPosts)).Methods("GET")
|
||||
r.Handle("/posts/{post_id}", ApiUserRequired(getPostById)).Methods("GET")
|
||||
|
||||
sr := r.PathPrefix("/channels/{id:[A-Za-z0-9]+}").Subrouter()
|
||||
sr.Handle("/create", ApiUserRequired(createPost)).Methods("POST")
|
||||
@@ -767,6 +768,41 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
|
||||
postId := params["post_id"]
|
||||
if len(postId) != 26 {
|
||||
c.SetInvalidParam("getPostById", "postId")
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Post().Get(postId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
list := result.Data.(*model.PostList)
|
||||
|
||||
if len(list.Order) != 1 {
|
||||
c.Err = model.NewAppError("getPostById", "Unable to get post", "")
|
||||
return
|
||||
}
|
||||
post := list.Posts[list.Order[0]]
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
|
||||
if !c.HasPermissionsToChannel(cchan, "getPostById") {
|
||||
return
|
||||
}
|
||||
|
||||
if HandleEtag(list.Etag(), w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag())
|
||||
w.Write([]byte(list.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user