subscription.go 977 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/miniflux2/reader/subscription"
  9. "github.com/miniflux/miniflux2/server/api/payload"
  10. "github.com/miniflux/miniflux2/server/core"
  11. )
  12. // GetSubscriptions is the API handler to find subscriptions.
  13. func (c *Controller) GetSubscriptions(ctx *core.Context, request *core.Request, response *core.Response) {
  14. websiteURL, err := payload.DecodeURLPayload(request.GetBody())
  15. if err != nil {
  16. response.Json().BadRequest(err)
  17. return
  18. }
  19. subscriptions, err := subscription.FindSubscriptions(websiteURL)
  20. if err != nil {
  21. response.Json().ServerError(errors.New("Unable to discover subscriptions"))
  22. return
  23. }
  24. if subscriptions == nil {
  25. response.Json().NotFound(fmt.Errorf("No subscription found"))
  26. return
  27. }
  28. response.Json().Standard(subscriptions)
  29. }