Little corrections

This commit is contained in:
Sinuhe Tellez 2017-03-24 00:30:57 -04:00
parent 15ba452994
commit 96c64350c2
2 changed files with 17 additions and 11 deletions

View File

@ -1,10 +1,7 @@
# dir2opds
Serve an OPDS server based on a directory
OPDS is an extension of Atom, to serve books. For more information: http://opds-spec.org
Some times you only have a directory with books and you want an OPDS, but to get from dir to OPDS you maybe need to do some work, this project aim to
simplely works.
It didn't pass the opds validator yet. But the plan is to get to that point.
dir2opds runs a OPDS server using a directory to generate the feeds.
# Installation

21
main.go
View File

@ -42,6 +42,10 @@ type AcquisitionFeed struct {
type CatalogFeed atom.Feed
const catalogType = "application/atom+xml;profile=opds-catalog"
const acquisitionType = "application/atom+xml;profile=opds-catalog;kind=acquisition"
const navegationType = "application/atom+xml;profile=opds-catalog;kind=navigation"
var (
port,
dirRoot,
@ -110,14 +114,13 @@ func isAcquisitionFeed(p string) (bool, error) {
}
func writeCatalogFeed(w io.Writer, u *url.URL) error {
//TODO: Do I am root
feed := &CatalogFeed{ID: u.Path, Title: "Catalog feed in " + u.Path}
feed.Author = &atom.Person{Name: author, Email: authorEmail, URI: authorUri}
feed.Updated = updated
feed.Link = []atom.Link{{
Rel: "start",
Href: "/",
Type: "application/atom+xml;profile=opds-catalog;kind=navigation",
Type: navegationType,
}}
abs_path := filepath.Join(dirRoot, u.Path)
@ -125,12 +128,19 @@ func writeCatalogFeed(w io.Writer, u *url.URL) error {
if err != nil {
return err
}
for _, fi := range fis {
isAcquisition, _ := isAcquisitionFeed(filepath.Join(abs_path, fi.Name()))
var linkType string
if linkType = catalogType; isAcquisition {
linkType = acquisitionType
}
link := atom.Link{
Rel: "subsection",
Title: fi.Name(),
Href: filepath.Join(u.EscapedPath(), url.PathEscape(fi.Name())),
Type: "application/atom+xml;profile=opds-catalog;kind=acquisition",
Type: linkType,
}
entry := &atom.Entry{
ID: filepath.Join(u.Path, fi.Name()),
@ -193,11 +203,10 @@ func writeAcquisitionFeed(w io.Writer, u *url.URL) error {
enc.Indent(" ", " ")
enc.Encode(feed)
return nil
return nil
}
func writeFileTo(w io.Writer, filepath string) error {
f, err := os.Open(filepath)
func writeFileTo(w io.Writer, p string) error {
f, err := os.Open(p)
if err != nil {
return err
}