Skip to content

Commit

Permalink
Merge branch 'main' into atom_version
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin authored Mar 12, 2024
2 parents a046d27 + 6d97f8b commit ddec897
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 400 deletions.
7 changes: 2 additions & 5 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package config // import "miniflux.app/v2/internal/config"

import (
"crypto/rand"
"fmt"
"sort"
"strings"
"time"

"miniflux.app/v2/internal/crypto"
"miniflux.app/v2/internal/version"
)

Expand Down Expand Up @@ -171,9 +171,6 @@ type Options struct {

// NewOptions returns Options with default values.
func NewOptions() *Options {
randomKey := make([]byte, 16)
rand.Read(randomKey)

return &Options{
HTTPS: defaultHTTPS,
logFile: defaultLogFile,
Expand Down Expand Up @@ -242,7 +239,7 @@ func NewOptions() *Options {
metricsPassword: defaultMetricsPassword,
watchdog: defaultWatchdog,
invidiousInstance: defaultInvidiousInstance,
proxyPrivateKey: randomKey,
proxyPrivateKey: crypto.GenerateRandomBytes(16),
webAuthn: defaultWebAuthn,
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (

// HashFromBytes returns a SHA-256 checksum of the input.
func HashFromBytes(value []byte) string {
sum := sha256.Sum256(value)
return fmt.Sprintf("%x", sum)
return fmt.Sprintf("%x", sha256.Sum256(value))
}

// Hash returns a SHA-256 checksum of a string.
Expand Down
31 changes: 31 additions & 0 deletions internal/reader/googleplay/googleplay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package googleplay // import "miniflux.app/v2/internal/reader/googleplay"

// Specs:
// https://support.google.com/googleplay/podcasts/answer/6260341
// https://www.google.com/schemas/play-podcasts/1.0/play-podcasts.xsd
type GooglePlayFeedElement struct {
GooglePlayAuthor string `xml:"http://www.google.com/schemas/play-podcasts/1.0 author"`
GooglePlayEmail string `xml:"http://www.google.com/schemas/play-podcasts/1.0 email"`
GooglePlayImage GooglePlayImageElement `xml:"http://www.google.com/schemas/play-podcasts/1.0 image"`
GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
GooglePlayCategory GooglePlayCategoryElement `xml:"http://www.google.com/schemas/play-podcasts/1.0 category"`
}

type GooglePlayItemElement struct {
GooglePlayAuthor string `xml:"http://www.google.com/schemas/play-podcasts/1.0 author"`
GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
GooglePlayExplicit string `xml:"http://www.google.com/schemas/play-podcasts/1.0 explicit"`
GooglePlayBlock string `xml:"http://www.google.com/schemas/play-podcasts/1.0 block"`
GooglePlayNewFeedURL string `xml:"http://www.google.com/schemas/play-podcasts/1.0 new-feed-url"`
}

type GooglePlayImageElement struct {
Href string `xml:"href,attr"`
}

type GooglePlayCategoryElement struct {
Text string `xml:"text,attr"`
}
75 changes: 75 additions & 0 deletions internal/reader/itunes/itunes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package itunes // import "miniflux.app/v2/internal/reader/itunes"

import "strings"

// Specs: https://help.apple.com/itc/podcasts_connect/#/itcb54353390
type ItunesFeedElement struct {
ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
ItunesBlock string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd block"`
ItunesCategories []ItunesCategoryElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd category"`
ItunesComplete string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd complete"`
ItunesCopyright string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd copyright"`
ItunesExplicit string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd explicit"`
ItunesImage ItunesImageElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd image"`
Keywords string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd keywords"`
ItunesNewFeedURL string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd new-feed-url"`
ItunesOwner ItunesOwnerElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd owner"`
ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
ItunesTitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd title"`
ItunesType string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd type"`
}

func (i *ItunesFeedElement) GetItunesCategories() []string {
var categories []string
for _, category := range i.ItunesCategories {
categories = append(categories, category.Text)
if category.SubCategory != nil {
categories = append(categories, category.SubCategory.Text)
}
}
return categories
}

type ItunesItemElement struct {
ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
ItunesEpisode string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd episode"`
ItunesEpisodeType string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd episodeType"`
ItunesExplicit string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd explicit"`
ItunesDuration string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd duration"`
ItunesImage ItunesImageElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd image"`
ItunesSeason string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd season"`
ItunesSubtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
ItunesTitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd title"`
ItunesTranscript string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd transcript"`
}

type ItunesImageElement struct {
Href string `xml:"href,attr"`
}

type ItunesCategoryElement struct {
Text string `xml:"text,attr"`
SubCategory *ItunesCategoryElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd category"`
}

type ItunesOwnerElement struct {
Name string `xml:"name"`
Email string `xml:"email"`
}

func (i *ItunesOwnerElement) String() string {
var name string

switch {
case i.Name != "":
name = i.Name
case i.Email != "":
name = i.Email
}

return strings.TrimSpace(name)
}
1 change: 1 addition & 0 deletions internal/reader/media/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])`)

// Element represents XML media elements.
// Specs: https://www.rssboard.org/media-rss
type Element struct {
MediaGroups []Group `xml:"http://search.yahoo.com/mrss/ group"`
MediaContents []Content `xml:"http://search.yahoo.com/mrss/ content"`
Expand Down
43 changes: 43 additions & 0 deletions internal/reader/rss/atom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package rss // import "miniflux.app/v2/internal/reader/rss"

import "strings"

type AtomAuthor struct {
Author AtomPerson `xml:"http://www.w3.org/2005/Atom author"`
}

func (a *AtomAuthor) String() string {
return a.Author.String()
}

type AtomPerson struct {
Name string `xml:"name"`
Email string `xml:"email"`
}

func (a *AtomPerson) String() string {
var name string

switch {
case a.Name != "":
name = a.Name
case a.Email != "":
name = a.Email
}

return strings.TrimSpace(name)
}

type AtomLink struct {
URL string `xml:"href,attr"`
Type string `xml:"type,attr"`
Rel string `xml:"rel,attr"`
Length string `xml:"length,attr"`
}

type AtomLinks struct {
Links []*AtomLink `xml:"http://www.w3.org/2005/Atom link"`
}
4 changes: 3 additions & 1 deletion internal/reader/rss/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
// Parse returns a normalized feed struct from a RSS feed.
func Parse(baseURL string, data io.ReadSeeker) (*model.Feed, error) {
feed := new(rssFeed)
if err := xml.NewXMLDecoder(data).Decode(feed); err != nil {
decoder := xml.NewXMLDecoder(data)
decoder.DefaultSpace = "rss"
if err := decoder.Decode(feed); err != nil {
return nil, fmt.Errorf("rss: unable to parse feed: %w", err)
}
return feed.Transform(baseURL), nil
Expand Down
Loading

0 comments on commit ddec897

Please sign in to comment.