From 63637d0b1ead005dec62b1377b9abcc8fdd07596 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 19 Feb 2018 00:46:59 -0600 Subject: [PATCH] add comment preview --- README.md | 2 ++ app/rest/api/rest.go | 11 +++++++++++ remark.rest | 12 ++++++++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 4c032009..bb3cb187 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/app/rest/api/rest.go b/app/rest/api/rest.go index 673f2879..a93b4b4a 100644 --- a/app/rest/api/rest.go +++ b/app/rest/api/rest.go @@ -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) { diff --git a/remark.rest b/remark.rest index cbf3fed0..6bea4403 100644 --- a/remark.rest +++ b/remark.rest @@ -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