opml.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 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. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/response/json"
  9. "github.com/miniflux/miniflux/http/response/xml"
  10. "github.com/miniflux/miniflux/reader/opml"
  11. )
  12. // Export is the API handler that export feeds to OPML.
  13. func (c *Controller) Export(w http.ResponseWriter, r *http.Request) {
  14. opmlHandler := opml.NewHandler(c.store)
  15. opml, err := opmlHandler.Export(context.New(r).UserID())
  16. if err != nil {
  17. json.ServerError(w, err)
  18. return
  19. }
  20. xml.OK(w, opml)
  21. }
  22. // Import is the API handler that import an OPML file.
  23. func (c *Controller) Import(w http.ResponseWriter, r *http.Request) {
  24. opmlHandler := opml.NewHandler(c.store)
  25. err := opmlHandler.Import(context.New(r).UserID(), r.Body)
  26. defer r.Body.Close()
  27. if err != nil {
  28. json.ServerError(w, err)
  29. return
  30. }
  31. json.Created(w, map[string]string{"message": "Feeds imported successfully"})
  32. }