1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-22 17:18:37 +00:00

Refactor feed discovery and avoid an extra HTTP request if the url provided is the feed

This commit is contained in:
Frédéric Guillot 2023-10-22 16:07:06 -07:00
parent 14e25ab9fe
commit eeaab72a9f
31 changed files with 455 additions and 200 deletions

View file

@ -4,8 +4,9 @@
package parser // import "miniflux.app/v2/internal/reader/parser"
import (
"bytes"
"encoding/xml"
"strings"
"io"
rxml "miniflux.app/v2/internal/reader/xml"
)
@ -20,12 +21,16 @@ const (
)
// DetectFeedFormat tries to guess the feed format from input data.
func DetectFeedFormat(data string) string {
if strings.HasPrefix(strings.TrimSpace(data), "{") {
func DetectFeedFormat(r io.ReadSeeker) string {
data := make([]byte, 512)
r.Read(data)
if bytes.HasPrefix(bytes.TrimSpace(data), []byte("{")) {
return FormatJSON
}
decoder := rxml.NewDecoder(strings.NewReader(data))
r.Seek(0, io.SeekStart)
decoder := rxml.NewDecoder(r)
for {
token, _ := decoder.Token()