From b97ca396c2062dca4e8023e24f0c46c61f696d24 Mon Sep 17 00:00:00 2001 From: Sinuhe Tellez Date: Fri, 15 May 2020 13:38:03 -0400 Subject: [PATCH 1/3] Fix hrel url generation and - add debug flag - add support for comics via mimetypes --- main.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index b92de3c..386d280 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,7 @@ var ( author = flag.String("author", "", "The server Feed author") authorURI = flag.String("uri", "", "The feed's author uri") authorEmail = flag.String("email", "", "The feed's author email") + debug = flag.Bool("debug", false, "If it is set it will log the requests") ) type acquisitionFeed struct { @@ -51,14 +52,21 @@ type acquisitionFeed struct { } func init() { - mime.AddExtensionType(".mobi", "application/x-mobipocket-ebook") - mime.AddExtensionType(".epub", "application/epub+zip") - mime.AddExtensionType(".fb2", "text/fb2+xml") + _ = mime.AddExtensionType(".mobi", "application/x-mobipocket-ebook") + _ = mime.AddExtensionType(".epub", "application/epub+zip") + _ = mime.AddExtensionType(".cbz", "application/x-cbz") + _ = mime.AddExtensionType(".cbr", "application/x-cbr") + _ = mime.AddExtensionType(".fb2", "text/fb2+xml") } func main() { + flag.Parse() + if *debug { + log.SetOutput(os.Stdout) + } + fmt.Println(startValues()) http.HandleFunc("/", errorHandler(handler)) @@ -67,14 +75,13 @@ func main() { } func startValues() string { - var result string - result = fmt.Sprintf("listening in: %s:%s", *host, *port) + result := fmt.Sprintf("listening in: %s:%s", *host, *port) return result } func handler(w http.ResponseWriter, req *http.Request) error { fpath := filepath.Join(*dirRoot, req.URL.Path) - + log.Printf("fpath:'%s'", fpath) fi, err := os.Stat(fpath) if err != nil { return err @@ -158,7 +165,7 @@ func getType(name string, pathType int) string { } func getHref(req *http.Request, name string) string { - return filepath.Join(req.URL.EscapedPath(), url.PathEscape(name)) + return filepath.Join(req.URL.RequestURI(), url.PathEscape(name)) } const ( From 680896480d284b0fcab986433241fec6be0368e6 Mon Sep 17 00:00:00 2001 From: Sinuhe Tellez Date: Fri, 15 May 2020 14:00:27 -0400 Subject: [PATCH 2/3] update change log fix debug flag --- CHANGELOG.md | 5 +++++ main.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a99dd7..b2587e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.0.4] - 2020-05-15 +### Added +- debug flag (idea from @clash04) +- comic support thanks to @clash04 +- fix hrel that didnt allow the download. (found the issue @clash04) ## [0.0.3] - 2019-03-10 ### Added diff --git a/main.go b/main.go index 386d280..a7f983d 100644 --- a/main.go +++ b/main.go @@ -63,8 +63,8 @@ func main() { flag.Parse() - if *debug { - log.SetOutput(os.Stdout) + if !*debug { + log.SetOutput(ioutil.Discard) } fmt.Println(startValues()) From 0920c683b8ea3834f0bda45667fb316a29512cc3 Mon Sep 17 00:00:00 2001 From: Sinuhe Tellez Date: Fri, 15 May 2020 14:04:52 -0400 Subject: [PATCH 3/3] fix typo --- main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a7f983d..7e09bfa 100644 --- a/main.go +++ b/main.go @@ -81,7 +81,9 @@ func startValues() string { func handler(w http.ResponseWriter, req *http.Request) error { fpath := filepath.Join(*dirRoot, req.URL.Path) + log.Printf("fpath:'%s'", fpath) + fi, err := os.Stat(fpath) if err != nil { return err @@ -113,7 +115,7 @@ func getContent(req *http.Request, dirpath string) (result []byte, err error) { return } -const navegationType = "application/atom+xml;profile=opds-catalog;kind=navigation" +const navigationType = "application/atom+xml;profile=opds-catalog;kind=navigation" func makeFeed(dirpath string, req *http.Request) atom.Feed { feedBuilder := opds.FeedBuilder. @@ -121,7 +123,7 @@ func makeFeed(dirpath string, req *http.Request) atom.Feed { Title("Catalog in " + req.URL.Path). Author(opds.AuthorBuilder.Name(*author).Email(*authorEmail).URI(*authorURI).Build()). Updated(time.Now()). - AddLink(opds.LinkBuilder.Rel("start").Href("/").Type(navegationType).Build()) + AddLink(opds.LinkBuilder.Rel("start").Href("/").Type(navigationType).Build()) fis, _ := ioutil.ReadDir(dirpath) for _, fi := range fis {