add comment preview

This commit is contained in:
Umputun
2018-02-19 00:46:59 -06:00
parent ef220f7adb
commit 63637d0b1e
3 changed files with 25 additions and 0 deletions
+2
View File
@@ -150,6 +150,8 @@ type Locator struct {
}
```
- `POST /api/v1/preview` - preview comment in html. Body is `Comment` to render
- `GET /api/v1/find?site=site-id&url=post-url&sort=fld&format=tree` - find all comments for given post
This is the primary call used by UI to show comments for given post. It can return comments in two formats - `plain` and `tree`.
+11
View File
@@ -84,6 +84,7 @@ func (s *Rest) Run(port int) {
rapi.Get("/count", s.countCtrl)
rapi.Get("/list", s.listCtrl)
rapi.Get("/config", s.configCtrl)
rapi.Post("/preview", s.previewCommentCtrl)
// protected routes, require auth
rapi.With(s.Authenticator.Auth(true)).Group(func(rauth chi.Router) {
@@ -169,6 +170,16 @@ func (s *Rest) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, JSON{"id": id, "locator": comment.Locator})
}
func (s *Rest) previewCommentCtrl(w http.ResponseWriter, r *http.Request) {
comment := store.Comment{}
if err := render.DecodeJSON(r.Body, &comment); err != nil {
rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't bind comment")
return
}
comment.Text = string(blackfriday.Run([]byte(comment.Text), blackfriday.WithNoExtensions()))
render.HTML(w, r, comment.Text)
}
// PUT /comment/{id}?site=siteID&url=post-url - update comment
func (s *Rest) updateCommentCtrl(w http.ResponseWriter, r *http.Request) {
+12
View File
@@ -20,6 +20,18 @@ Content-Type: application/json
}
}
### preview comment
POST {{host}}/api/v1/preview
Content-Type: application/json
{
"text": "comment *blah* http://radio-t.com",
"locator": {
"url": "https://radio-t.com/blah1",
"site": "remark"
}
}
### update comment
PUT {{host}}/api/v1/comment/7b88d7a91353ab206cb63cdca18fb26bcb30205b?site=remark&url=https://radio-t.com/blah1
Content-Type: application/json