mirror of
https://codeberg.org/librarian/feeds
synced 2024-12-06 19:16:24 +01:00
RssEnclosure.Length remains string to not break the API
code now gofmt formatted
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Generates Atom feed as XML
|
||||
@@ -110,7 +110,6 @@ func newAtomEntry(i *Item) *AtomEntry {
|
||||
name, email = i.Author.Name, i.Author.Email
|
||||
}
|
||||
|
||||
|
||||
x := &AtomEntry{
|
||||
Title: i.Title,
|
||||
Link: &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type},
|
||||
@@ -119,11 +118,12 @@ func newAtomEntry(i *Item) *AtomEntry {
|
||||
Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created),
|
||||
}
|
||||
|
||||
if(i.Link.Length>0) {
|
||||
i.Link.Rel = "enclosure"
|
||||
x.Link = &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type, Length: strconv.FormatInt(i.Link.Length,10)}
|
||||
}
|
||||
int_Length, err := strconv.ParseInt(i.Link.Length, 10, 64)
|
||||
|
||||
if err == nil && (int_Length > 0 || i.Link.Type != "") {
|
||||
i.Link.Rel = "enclosure"
|
||||
x.Link = &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type, Length: i.Link.Length}
|
||||
}
|
||||
|
||||
if len(name) > 0 || len(email) > 0 {
|
||||
x.Author = &AtomAuthor{AtomPerson: AtomPerson{Name: name, Email: email}}
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
Href, Rel,Type string
|
||||
Length int64
|
||||
Href, Rel, Type, Length string
|
||||
}
|
||||
|
||||
type Author struct {
|
||||
@@ -25,7 +24,6 @@ type Item struct {
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
|
||||
type Feed struct {
|
||||
Title string
|
||||
Link *Link
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ func TestFeed(t *testing.T) {
|
||||
},
|
||||
&Item{
|
||||
Title: "Never Gonna Give You Up Mp3",
|
||||
Link: &Link{Href: "http://example.com/RickRoll.mp3",Length: 123456, Type: "audio/mpeg"},
|
||||
Link: &Link{Href: "http://example.com/RickRoll.mp3", Length: "123456", Type: "audio/mpeg"},
|
||||
Description: "Never gonna give you up - Never gonna let you down.",
|
||||
Created: now,
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@ package feeds
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -76,7 +77,7 @@ type RssEnclosure struct {
|
||||
//RSS 2.0 <enclosure url="http://example.com/file.mp3" length="123456789" type="audio/mpeg" />
|
||||
XMLName xml.Name `xml:"enclosure"`
|
||||
Url string `xml:"url,attr"`
|
||||
Length int64 `xml:"length,attr"`
|
||||
Length string `xml:"length,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
}
|
||||
|
||||
@@ -93,7 +94,10 @@ func newRssItem(i *Item) *RssItem {
|
||||
Guid: i.Id,
|
||||
PubDate: anyTimeFormat(time.RFC822, i.Created, i.Updated),
|
||||
}
|
||||
if(i.Link.Length > 0 || i.Link.Type != ""){
|
||||
|
||||
int_Length, err := strconv.ParseInt(i.Link.Length, 10, 64)
|
||||
|
||||
if err == nil && (int_Length > 0 || i.Link.Type != "") {
|
||||
item.Enclosure = &RssEnclosure{Url: i.Link.Href, Type: i.Link.Type, Length: i.Link.Length}
|
||||
}
|
||||
if i.Author != nil {
|
||||
|
||||
Reference in New Issue
Block a user