2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-20 06:10:04 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package atom // import "miniflux.app/v2/internal/reader/atom"
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
import (
|
2023-10-22 04:50:29 +02:00
|
|
|
"fmt"
|
2017-11-20 06:10:04 +01:00
|
|
|
"io"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
xml_decoder "miniflux.app/v2/internal/reader/xml"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2017-11-21 03:34:11 +01:00
|
|
|
// Parse returns a normalized feed struct from a Atom feed.
|
2024-03-12 13:11:56 +01:00
|
|
|
func Parse(baseURL string, r io.ReadSeeker, version string) (*model.Feed, error) {
|
2024-03-16 00:39:32 +01:00
|
|
|
switch version {
|
|
|
|
case "0.3":
|
|
|
|
atomFeed := new(Atom03Feed)
|
|
|
|
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
|
|
|
|
return nil, fmt.Errorf("atom: unable to parse Atom 0.3 feed: %w", err)
|
|
|
|
}
|
|
|
|
return NewAtom03Adapter(atomFeed).BuildFeed(baseURL), nil
|
|
|
|
default:
|
|
|
|
atomFeed := new(Atom10Feed)
|
|
|
|
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
|
|
|
|
return nil, fmt.Errorf("atom: unable to parse Atom 1.0 feed: %w", err)
|
|
|
|
}
|
|
|
|
return NewAtom10Adapter(atomFeed).BuildFeed(baseURL), nil
|
2019-12-23 07:18:21 +01:00
|
|
|
}
|
|
|
|
}
|