miniflux/internal/api/subscription.go

49 lines
1.4 KiB
Go
Raw Normal View History

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
2017-11-20 06:10:04 +01:00
package api // import "miniflux.app/v2/internal/api"
2017-11-20 06:10:04 +01:00
import (
2021-01-04 22:49:28 +01:00
json_parser "encoding/json"
"net/http"
2017-12-13 06:48:13 +01:00
"miniflux.app/v2/internal/http/response/json"
"miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/reader/subscription"
"miniflux.app/v2/internal/validator"
2017-11-20 06:10:04 +01:00
)
2021-01-04 22:49:28 +01:00
func (h *handler) discoverSubscriptions(w http.ResponseWriter, r *http.Request) {
var subscriptionDiscoveryRequest model.SubscriptionDiscoveryRequest
if err := json_parser.NewDecoder(r.Body).Decode(&subscriptionDiscoveryRequest); err != nil {
json.BadRequest(w, r, err)
return
}
if validationErr := validator.ValidateSubscriptionDiscovery(&subscriptionDiscoveryRequest); validationErr != nil {
json.BadRequest(w, r, validationErr.Error())
2017-11-20 06:10:04 +01:00
return
}
subscriptions, finderErr := subscription.FindSubscriptions(
2021-01-04 22:49:28 +01:00
subscriptionDiscoveryRequest.URL,
subscriptionDiscoveryRequest.UserAgent,
2021-03-23 04:27:58 +01:00
subscriptionDiscoveryRequest.Cookie,
2021-01-04 22:49:28 +01:00
subscriptionDiscoveryRequest.Username,
subscriptionDiscoveryRequest.Password,
subscriptionDiscoveryRequest.FetchViaProxy,
subscriptionDiscoveryRequest.AllowSelfSignedCertificates,
)
if finderErr != nil {
json.ServerError(w, r, finderErr)
2017-11-20 06:10:04 +01:00
return
}
if subscriptions == nil {
2018-10-08 03:42:43 +02:00
json.NotFound(w, r)
2017-11-20 06:10:04 +01:00
return
}
json.OK(w, r, subscriptions)
2017-11-20 06:10:04 +01:00
}