mirror of
https://github.com/miniflux/v2.git
synced 2025-09-05 18:41:01 +00:00
Simplify feed parser and format detection
- Avoid doing multiple buffer copies - Move parser and format detection logic to its own package
This commit is contained in:
parent
d5ff4191b6
commit
5870f04260
11 changed files with 229 additions and 221 deletions
|
@ -5,15 +5,15 @@
|
|||
package subscription // import "miniflux.app/reader/subscription"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"miniflux.app/errors"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/reader/feed"
|
||||
"miniflux.app/reader/parser"
|
||||
"miniflux.app/timer"
|
||||
"miniflux.app/url"
|
||||
|
||||
|
@ -56,20 +56,12 @@ func FindSubscriptions(websiteURL, userAgent, username, password string) (Subscr
|
|||
return nil, errors.NewLocalizedError(errEmptyBody)
|
||||
}
|
||||
|
||||
body, err := response.NormalizeBodyEncoding()
|
||||
if err != nil {
|
||||
if err := response.EnsureUnicodeBody(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
size, _ := io.Copy(&buffer, body)
|
||||
if size == 0 {
|
||||
return nil, errors.NewLocalizedError(errEmptyBody)
|
||||
}
|
||||
|
||||
reader := bytes.NewReader(buffer.Bytes())
|
||||
|
||||
if format := feed.DetectFeedFormat(reader); format != feed.FormatUnknown {
|
||||
body := response.String()
|
||||
if format := parser.DetectFeedFormat(body); format != parser.FormatUnknown {
|
||||
var subscriptions Subscriptions
|
||||
subscriptions = append(subscriptions, &Subscription{
|
||||
Title: response.EffectiveURL,
|
||||
|
@ -80,8 +72,7 @@ func FindSubscriptions(websiteURL, userAgent, username, password string) (Subscr
|
|||
return subscriptions, nil
|
||||
}
|
||||
|
||||
reader.Seek(0, io.SeekStart)
|
||||
return parseDocument(response.EffectiveURL, bytes.NewReader(buffer.Bytes()))
|
||||
return parseDocument(response.EffectiveURL, strings.NewReader(body))
|
||||
}
|
||||
|
||||
func parseDocument(websiteURL string, data io.Reader) (Subscriptions, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue