eksterd: make preview also available as a post request
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
44b73e1c79
commit
9df63af33c
|
@ -88,7 +88,7 @@ func (c *Client) microsubPostRequest(action string, args map[string]string) (*ht
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
msg, _ := ioutil.ReadAll(res.Body)
|
msg, _ := ioutil.ReadAll(res.Body)
|
||||||
return nil, fmt.Errorf("unsuccessful response: %d: %q", res.StatusCode, string(msg))
|
return nil, fmt.Errorf("unsuccessful response: %d: %q", res.StatusCode, strings.TrimSpace(string(msg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, err
|
return res, err
|
||||||
|
@ -116,7 +116,7 @@ func (c *Client) microsubPostFormRequest(action string, args map[string]string,
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
msg, _ := ioutil.ReadAll(res.Body)
|
msg, _ := ioutil.ReadAll(res.Body)
|
||||||
return nil, fmt.Errorf("unsuccessful response: %d: %q", res.StatusCode, string(msg))
|
return nil, fmt.Errorf("unsuccessful response: %d: %q", res.StatusCode, strings.TrimSpace(string(msg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, err
|
return res, err
|
||||||
|
@ -180,7 +180,7 @@ func (c *Client) TimelineGet(before, after, channel string) (microsub.Timeline,
|
||||||
func (c *Client) PreviewURL(url string) (microsub.Timeline, error) {
|
func (c *Client) PreviewURL(url string) (microsub.Timeline, error) {
|
||||||
args := make(map[string]string)
|
args := make(map[string]string)
|
||||||
args["url"] = url
|
args["url"] = url
|
||||||
res, err := c.microsubGetRequest("preview", args)
|
res, err := c.microsubPostRequest("preview", args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return microsub.Timeline{}, err
|
return microsub.Timeline{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, "internal server error", 500)
|
http.Error(w, "internal server error", 500)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 400)
|
http.Error(w, fmt.Sprintf("unknown action %s", action), 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -182,6 +182,13 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, []string{})
|
respondJSON(w, []string{})
|
||||||
|
} else if action == "preview" {
|
||||||
|
timeline, err := h.backend.PreviewURL(values.Get("url"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
respondJSON(w, timeline)
|
||||||
} else if action == "search" {
|
} else if action == "search" {
|
||||||
query := values.Get("query")
|
query := values.Get("query")
|
||||||
channel := values.Get("channel")
|
channel := values.Get("channel")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user