mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Add RSS-Bridge integration
This commit is contained in:
parent
5e6c054345
commit
120aabfbce
29 changed files with 161 additions and 5 deletions
45
internal/integration/rssbridge/rssbridge.go
Normal file
45
internal/integration/rssbridge/rssbridge.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package rssbridge // import "miniflux.app/integration/rssbridge"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Bridge struct {
|
||||
URL string `json:"url"`
|
||||
BridgeMeta BridgeMeta `json:"bridgeMeta"`
|
||||
}
|
||||
|
||||
type BridgeMeta struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func DetectBridges(rssbridgeURL, websiteURL string) (bridgeResponse []Bridge, err error) {
|
||||
u, err := url.Parse(rssbridgeURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values := u.Query()
|
||||
values.Add("action", "findfeed")
|
||||
values.Add("format", "atom")
|
||||
values.Add("url", websiteURL)
|
||||
u.RawQuery = values.Encode()
|
||||
|
||||
response, err := http.Get(u.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode == http.StatusNotFound {
|
||||
return
|
||||
}
|
||||
if response.StatusCode > 400 {
|
||||
return nil, fmt.Errorf("RSS-Bridge: server failure (%d)", response.StatusCode)
|
||||
}
|
||||
if err := json.NewDecoder(response.Body).Decode(&bridgeResponse); err != nil {
|
||||
return nil, fmt.Errorf("RSS-Bridge: unable to decode bridge response: %w", err)
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue