opml.go 940 B

12345678910111213141516171819202122232425262728293031323334353637
  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 // import "miniflux.app/api"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/json"
  9. "miniflux.app/http/response/xml"
  10. "miniflux.app/reader/opml"
  11. )
  12. func (h *handler) exportFeeds(w http.ResponseWriter, r *http.Request) {
  13. opmlHandler := opml.NewHandler(h.store)
  14. opml, err := opmlHandler.Export(request.UserID(r))
  15. if err != nil {
  16. json.ServerError(w, r, err)
  17. return
  18. }
  19. xml.OK(w, r, opml)
  20. }
  21. func (h *handler) importFeeds(w http.ResponseWriter, r *http.Request) {
  22. opmlHandler := opml.NewHandler(h.store)
  23. err := opmlHandler.Import(request.UserID(r), r.Body)
  24. defer r.Body.Close()
  25. if err != nil {
  26. json.ServerError(w, r, err)
  27. return
  28. }
  29. json.Created(w, r, map[string]string{"message": "Feeds imported successfully"})
  30. }