Little corrections
This commit is contained in:
parent
15ba452994
commit
96c64350c2
@ -1,10 +1,7 @@
|
|||||||
# dir2opds
|
# 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
|
dir2opds runs a OPDS server using a directory to generate the feeds.
|
||||||
simplely works.
|
|
||||||
|
|
||||||
It didn't pass the opds validator yet. But the plan is to get to that point.
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
|
21
main.go
21
main.go
@ -42,6 +42,10 @@ type AcquisitionFeed struct {
|
|||||||
|
|
||||||
type CatalogFeed atom.Feed
|
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 (
|
var (
|
||||||
port,
|
port,
|
||||||
dirRoot,
|
dirRoot,
|
||||||
@ -110,14 +114,13 @@ func isAcquisitionFeed(p string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeCatalogFeed(w io.Writer, u *url.URL) 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 := &CatalogFeed{ID: u.Path, Title: "Catalog feed in " + u.Path}
|
||||||
feed.Author = &atom.Person{Name: author, Email: authorEmail, URI: authorUri}
|
feed.Author = &atom.Person{Name: author, Email: authorEmail, URI: authorUri}
|
||||||
feed.Updated = updated
|
feed.Updated = updated
|
||||||
feed.Link = []atom.Link{{
|
feed.Link = []atom.Link{{
|
||||||
Rel: "start",
|
Rel: "start",
|
||||||
Href: "/",
|
Href: "/",
|
||||||
Type: "application/atom+xml;profile=opds-catalog;kind=navigation",
|
Type: navegationType,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
abs_path := filepath.Join(dirRoot, u.Path)
|
abs_path := filepath.Join(dirRoot, u.Path)
|
||||||
@ -125,12 +128,19 @@ func writeCatalogFeed(w io.Writer, u *url.URL) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
|
isAcquisition, _ := isAcquisitionFeed(filepath.Join(abs_path, fi.Name()))
|
||||||
|
|
||||||
|
var linkType string
|
||||||
|
if linkType = catalogType; isAcquisition {
|
||||||
|
linkType = acquisitionType
|
||||||
|
}
|
||||||
link := atom.Link{
|
link := atom.Link{
|
||||||
Rel: "subsection",
|
Rel: "subsection",
|
||||||
Title: fi.Name(),
|
Title: fi.Name(),
|
||||||
Href: filepath.Join(u.EscapedPath(), url.PathEscape(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{
|
entry := &atom.Entry{
|
||||||
ID: filepath.Join(u.Path, fi.Name()),
|
ID: filepath.Join(u.Path, fi.Name()),
|
||||||
@ -193,11 +203,10 @@ func writeAcquisitionFeed(w io.Writer, u *url.URL) error {
|
|||||||
enc.Indent(" ", " ")
|
enc.Indent(" ", " ")
|
||||||
enc.Encode(feed)
|
enc.Encode(feed)
|
||||||
return nil
|
return nil
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeFileTo(w io.Writer, filepath string) error {
|
func writeFileTo(w io.Writer, p string) error {
|
||||||
f, err := os.Open(filepath)
|
f, err := os.Open(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user