From 96c64350c252da737f7b0a2f3ee6e4489484b993 Mon Sep 17 00:00:00 2001 From: Sinuhe Tellez Date: Fri, 24 Mar 2017 00:30:57 -0400 Subject: [PATCH] Little corrections --- README.md | 7 ++----- main.go | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a5f9cf7..cfb8a7e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index c5b9fdc..04c9fa3 100644 --- a/main.go +++ b/main.go @@ -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 }