subscription.go 923 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package api
  5. import (
  6. "errors"
  7. "fmt"
  8. "github.com/miniflux/miniflux/http/handler"
  9. "github.com/miniflux/miniflux/reader/subscription"
  10. )
  11. // GetSubscriptions is the API handler to find subscriptions.
  12. func (c *Controller) GetSubscriptions(ctx *handler.Context, request *handler.Request, response *handler.Response) {
  13. websiteURL, err := decodeURLPayload(request.Body())
  14. if err != nil {
  15. response.JSON().BadRequest(err)
  16. return
  17. }
  18. subscriptions, err := subscription.FindSubscriptions(websiteURL)
  19. if err != nil {
  20. response.JSON().ServerError(errors.New("Unable to discover subscriptions"))
  21. return
  22. }
  23. if subscriptions == nil {
  24. response.JSON().NotFound(fmt.Errorf("No subscription found"))
  25. return
  26. }
  27. response.JSON().Standard(subscriptions)
  28. }