2023-06-19 14:42:47 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-29 18:56:40 -07:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
package api // import "miniflux.app/v2/internal/api"
|
2018-04-29 18:56:40 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/json"
|
|
|
|
"miniflux.app/v2/internal/http/response/xml"
|
|
|
|
"miniflux.app/v2/internal/reader/opml"
|
2018-04-29 18:56:40 -07:00
|
|
|
)
|
|
|
|
|
2018-11-11 10:22:47 -08:00
|
|
|
func (h *handler) exportFeeds(w http.ResponseWriter, r *http.Request) {
|
|
|
|
opmlHandler := opml.NewHandler(h.store)
|
2023-09-27 21:15:32 -07:00
|
|
|
opmlExport, err := opmlHandler.Export(request.UserID(r))
|
2018-04-29 18:56:40 -07:00
|
|
|
if err != nil {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.ServerError(w, r, err)
|
2018-04-29 18:56:40 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-09-27 21:15:32 -07:00
|
|
|
xml.OK(w, r, opmlExport)
|
2018-04-29 18:56:40 -07:00
|
|
|
}
|
|
|
|
|
2018-11-11 10:22:47 -08:00
|
|
|
func (h *handler) importFeeds(w http.ResponseWriter, r *http.Request) {
|
|
|
|
opmlHandler := opml.NewHandler(h.store)
|
2018-09-03 14:26:40 -07:00
|
|
|
err := opmlHandler.Import(request.UserID(r), r.Body)
|
2018-04-29 18:56:40 -07:00
|
|
|
defer r.Body.Close()
|
|
|
|
if err != nil {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.ServerError(w, r, err)
|
2018-04-29 18:56:40 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-07 18:42:43 -07:00
|
|
|
json.Created(w, r, map[string]string{"message": "Feeds imported successfully"})
|
2018-04-29 18:56:40 -07:00
|
|
|
}
|