Change feed url from query param
parent
7ee5f9829c
commit
78e38f84d1
|
|
@ -90,8 +90,7 @@ func Test_Core(t *testing.T) {
|
|||
},
|
||||
{
|
||||
method: "get",
|
||||
path: "api/feed",
|
||||
body: rssserver.URL + "/feed",
|
||||
path: "api/feed/" + rssserver.URL + "/feed",
|
||||
status: 200,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,12 +89,14 @@ func (s *Server) api(w http.ResponseWriter, r *http.Request) {
|
|||
func (s *Server) feed(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
switch advance(r) {
|
||||
v := advance(r)
|
||||
switch v {
|
||||
case "item":
|
||||
s.getFeedItem(w, r)
|
||||
case "tag":
|
||||
s.getFeedTag(w, r)
|
||||
case "":
|
||||
default:
|
||||
r.URL.Path = v + "/" + r.URL.Path
|
||||
s.getFeed(w, r)
|
||||
}
|
||||
case "POST":
|
||||
|
|
@ -172,23 +174,20 @@ func (s *Server) getFeedItem(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (s *Server) getFeed(w http.ResponseWriter, r *http.Request) {
|
||||
url, err := url.ParseQuery(r.URL.RawQuery)
|
||||
if err != nil {
|
||||
logger.Logf("cannot get feed to read: %v", err)
|
||||
s.mybad(w, r)
|
||||
var err error
|
||||
url := r.URL.Path
|
||||
if url == "" {
|
||||
s.bad(w, r)
|
||||
return
|
||||
}
|
||||
limit := 20
|
||||
if url.Get("limit") != "" {
|
||||
limit, err = strconv.Atoi(url.Get("limit"))
|
||||
if err != nil {
|
||||
s.bad(w, r)
|
||||
return
|
||||
}
|
||||
if limitB, err := strconv.Atoi(strings.Split(url, ":")[0]); err == nil {
|
||||
limit = limitB
|
||||
url = url[len(strings.Split(url, ":")[0])+1:]
|
||||
}
|
||||
feedBody, err := s.getFeedHandler(url.Get("url"), limit)
|
||||
feedBody, err := s.getFeedHandler(url, limit)
|
||||
if err != nil {
|
||||
logger.Logf("cannot get feed %s: %v", url.Get("url"), err)
|
||||
logger.Logf("cannot get feed %s: %v", url, err)
|
||||
s.mybad(w, r)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func Test_Server(t *testing.T) {
|
|||
if err := checkStatus("GET", "api", http.StatusNotFound); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("GET", "api/feed", http.StatusOK); err != nil {
|
||||
if err := checkStatus("GET", "api/feed", http.StatusBadRequest); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("POST", "api/feed", http.StatusBadRequest); err != nil {
|
||||
|
|
@ -46,7 +46,10 @@ func Test_Server(t *testing.T) {
|
|||
if err := checkStatus("PUT", "api/feed", http.StatusOK, `{"url":"localhost:1234", "refresh":"1m", "tags":["a", "b"]}`); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("GET", "api/feed?url=localhost_1234", http.StatusOK); err != nil {
|
||||
if err := checkStatus("GET", "api/feed/localhost_1234", http.StatusOK); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("GET", "api/feed/1:localhost_1234", http.StatusOK); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("GET", "api/feed/item/localhost_1234", http.StatusOK); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue