Files
opds-proxy/opds/opds.go
Evan Buss c63b20551f refactor: home page / url passing
We now allow multiple OPDS feeds to be pre-defined and displayed
on the homepage. As a result we need to pass the feed navigation
URLs via query parameter rather than a subpath which would only
support proxying to a single OPDS feed.

The feed is passed via the q= query parameter and any relative
links from the OPDS XML are resolved to a complete URL with
domain / scheme.

We also check the "Content-Type" header in the response
received from the OPDS feed to determine whether to parse
an OPDS catalog or just proxy the raw response back (images / files).
2024-07-06 16:06:08 -04:00

35 lines
669 B
Go

package opds
import (
"encoding/xml"
"io"
"strings"
)
func ParseFeed(r io.Reader) (*Feed, error) {
var feed Feed
err := xml.NewDecoder(r).Decode(&feed)
if err != nil {
return nil, err
}
return &feed, nil
}
func (link Link) IsDownload() bool {
return link.Rel == "http://opds-spec.org/acquisition"
}
func (link Link) IsImage(category string) bool {
if strings.HasPrefix(link.TypeLink, "image") && !strings.HasPrefix(link.Href, "data") {
return strings.Contains(link.Rel, category)
}
return false
}
func (link Link) IsNavigation() bool {
return link.TypeLink == "application/atom+xml;type=feed;profile=opds-catalog" || link.Rel == "subsection"
}