commit
4eeea88071
@ -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/),
|
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).
|
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
|
## [0.0.3] - 2019-03-10
|
||||||
### Added
|
### Added
|
||||||
|
25
main.go
25
main.go
@ -42,6 +42,7 @@ var (
|
|||||||
author = flag.String("author", "", "The server Feed author")
|
author = flag.String("author", "", "The server Feed author")
|
||||||
authorURI = flag.String("uri", "", "The feed's author uri")
|
authorURI = flag.String("uri", "", "The feed's author uri")
|
||||||
authorEmail = flag.String("email", "", "The feed's author email")
|
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 {
|
type acquisitionFeed struct {
|
||||||
@ -51,14 +52,21 @@ type acquisitionFeed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
mime.AddExtensionType(".mobi", "application/x-mobipocket-ebook")
|
_ = mime.AddExtensionType(".mobi", "application/x-mobipocket-ebook")
|
||||||
mime.AddExtensionType(".epub", "application/epub+zip")
|
_ = mime.AddExtensionType(".epub", "application/epub+zip")
|
||||||
mime.AddExtensionType(".fb2", "text/fb2+xml")
|
_ = mime.AddExtensionType(".cbz", "application/x-cbz")
|
||||||
|
_ = mime.AddExtensionType(".cbr", "application/x-cbr")
|
||||||
|
_ = mime.AddExtensionType(".fb2", "text/fb2+xml")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if !*debug {
|
||||||
|
log.SetOutput(ioutil.Discard)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(startValues())
|
fmt.Println(startValues())
|
||||||
|
|
||||||
http.HandleFunc("/", errorHandler(handler))
|
http.HandleFunc("/", errorHandler(handler))
|
||||||
@ -67,14 +75,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startValues() string {
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, req *http.Request) error {
|
func handler(w http.ResponseWriter, req *http.Request) error {
|
||||||
fpath := filepath.Join(*dirRoot, req.URL.Path)
|
fpath := filepath.Join(*dirRoot, req.URL.Path)
|
||||||
|
|
||||||
|
log.Printf("fpath:'%s'", fpath)
|
||||||
|
|
||||||
fi, err := os.Stat(fpath)
|
fi, err := os.Stat(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -106,7 +115,7 @@ func getContent(req *http.Request, dirpath string) (result []byte, err error) {
|
|||||||
return
|
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 {
|
func makeFeed(dirpath string, req *http.Request) atom.Feed {
|
||||||
feedBuilder := opds.FeedBuilder.
|
feedBuilder := opds.FeedBuilder.
|
||||||
@ -114,7 +123,7 @@ func makeFeed(dirpath string, req *http.Request) atom.Feed {
|
|||||||
Title("Catalog in " + req.URL.Path).
|
Title("Catalog in " + req.URL.Path).
|
||||||
Author(opds.AuthorBuilder.Name(*author).Email(*authorEmail).URI(*authorURI).Build()).
|
Author(opds.AuthorBuilder.Name(*author).Email(*authorEmail).URI(*authorURI).Build()).
|
||||||
Updated(time.Now()).
|
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)
|
fis, _ := ioutil.ReadDir(dirpath)
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
@ -158,7 +167,7 @@ func getType(name string, pathType int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHref(req *http.Request, name string) 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 (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user