Display cover, configure calibre path
This commit is contained in:
parent
c565a9318a
commit
daa6d2152e
@ -3,13 +3,15 @@ package bouquins
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/c2h5oh/datasize"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/c2h5oh/datasize"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -35,6 +37,7 @@ const (
|
|||||||
URL_JS = "/js/"
|
URL_JS = "/js/"
|
||||||
URL_CSS = "/css/"
|
URL_CSS = "/css/"
|
||||||
URL_FONTS = "/fonts/"
|
URL_FONTS = "/fonts/"
|
||||||
|
URL_CALIBRE = "/calibre/"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bouquins struct {
|
type Bouquins struct {
|
||||||
@ -188,8 +191,12 @@ func TemplatesFunc() *template.Template {
|
|||||||
"humanSize": func(sz int64) string {
|
"humanSize": func(sz int64) string {
|
||||||
return datasize.ByteSize(sz).HumanReadable()
|
return datasize.ByteSize(sz).HumanReadable()
|
||||||
},
|
},
|
||||||
|
"bookCover": func(book *BookFull) string {
|
||||||
|
fmt.Println(book.Path)
|
||||||
|
return "/calibre/" + url.PathEscape(book.Path) + "/cover.jpg"
|
||||||
|
},
|
||||||
"bookLink": func(data *BookData, book *BookFull) string {
|
"bookLink": func(data *BookData, book *BookFull) string {
|
||||||
return "/images/" + url.QueryEscape(book.Path) + "/" + url.QueryEscape(data.Name) + "." + strings.ToLower(data.Format)
|
return "/calibre/" + url.PathEscape(book.Path) + "/" + url.PathEscape(data.Name) + "." + strings.ToLower(data.Format)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return tpl
|
return tpl
|
||||||
|
11
main.go
11
main.go
@ -15,6 +15,7 @@ import (
|
|||||||
type BouquinsConf struct {
|
type BouquinsConf struct {
|
||||||
BindAddress string `json:"bind-address"`
|
BindAddress string `json:"bind-address"`
|
||||||
DbPath string `json:"db-path"`
|
DbPath string `json:"db-path"`
|
||||||
|
CalibrePath string `json:"calibre-path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
@ -35,8 +36,11 @@ func ReadConfig() (*BouquinsConf, error) {
|
|||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
// default values
|
// default values
|
||||||
|
if conf.CalibrePath == "" {
|
||||||
|
conf.CalibrePath = "."
|
||||||
|
}
|
||||||
if conf.DbPath == "" {
|
if conf.DbPath == "" {
|
||||||
conf.DbPath = "calibre.db"
|
conf.DbPath = conf.CalibrePath + "/metadata.db"
|
||||||
}
|
}
|
||||||
if conf.BindAddress == "" {
|
if conf.BindAddress == "" {
|
||||||
conf.BindAddress = ":9000"
|
conf.BindAddress = ":9000"
|
||||||
@ -67,15 +71,16 @@ func initApp() *BouquinsConf {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
assets()
|
assets(conf.CalibrePath)
|
||||||
router(app)
|
router(app)
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
func assets() {
|
func assets(calibre string) {
|
||||||
http.Handle(URL_JS, http.FileServer(http.Dir("assets")))
|
http.Handle(URL_JS, http.FileServer(http.Dir("assets")))
|
||||||
http.Handle(URL_CSS, http.FileServer(http.Dir("assets")))
|
http.Handle(URL_CSS, http.FileServer(http.Dir("assets")))
|
||||||
http.Handle(URL_FONTS, http.FileServer(http.Dir("assets")))
|
http.Handle(URL_FONTS, http.FileServer(http.Dir("assets")))
|
||||||
|
http.Handle(URL_CALIBRE, http.StripPrefix(URL_CALIBRE, http.FileServer(http.Dir(calibre))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func router(app *Bouquins) {
|
func router(app *Bouquins) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
{{ if .Has_cover }}
|
{{ if .Has_cover }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<img :src="bookCover(book)" alt="Pas de couverture" title="Couverture" class="img-responsive img-rounded"/>
|
<img src="{{ bookCover .BookFull }}" alt="Pas de couverture" title="Couverture" class="img-responsive img-rounded" width="400px"/>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
Loading…
Reference in New Issue
Block a user