Merge pull request #6 from dubyte/release_0_4_0

Release 0 4 0
This commit is contained in:
Sinuhe Tellez Rivera 2020-05-20 00:01:30 -04:00 committed by GitHub
commit 4eeea88071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -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

25
main.go
View File

@ -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(ioutil.Discard)
}
fmt.Println(startValues())
http.HandleFunc("/", errorHandler(handler))
@ -67,14 +75,15 @@ 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
@ -106,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.
@ -114,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 {
@ -158,7 +167,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 (