2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package api // import "miniflux.app/v2/internal/api"
|
2017-11-20 00:10:04 -05:00
|
|
|
|
|
|
|
import (
|
2021-01-04 16:49:28 -05:00
|
|
|
json_parser "encoding/json"
|
2018-04-29 19:35:04 -04:00
|
|
|
"net/http"
|
2017-12-13 00:48:13 -05:00
|
|
|
|
2023-08-10 22:46:45 -04: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 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
2021-01-04 16:49:28 -05: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 00:10:04 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-20 00:38:21 -04:00
|
|
|
subscriptions, finderErr := subscription.FindSubscriptions(
|
2021-01-04 16:49:28 -05:00
|
|
|
subscriptionDiscoveryRequest.URL,
|
|
|
|
subscriptionDiscoveryRequest.UserAgent,
|
2021-03-22 23:27:58 -04:00
|
|
|
subscriptionDiscoveryRequest.Cookie,
|
2021-01-04 16:49:28 -05:00
|
|
|
subscriptionDiscoveryRequest.Username,
|
|
|
|
subscriptionDiscoveryRequest.Password,
|
|
|
|
subscriptionDiscoveryRequest.FetchViaProxy,
|
2021-02-21 16:42:49 -05:00
|
|
|
subscriptionDiscoveryRequest.AllowSelfSignedCertificates,
|
2018-06-20 01:58:29 -04:00
|
|
|
)
|
2018-10-20 00:38:21 -04:00
|
|
|
if finderErr != nil {
|
|
|
|
json.ServerError(w, r, finderErr)
|
2017-11-20 00:10:04 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if subscriptions == nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
json.NotFound(w, r)
|
2017-11-20 00:10:04 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-19 22:27:05 -04:00
|
|
|
json.OK(w, r, subscriptions)
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|