Added interval flag
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,4 +5,6 @@ h.html
|
|||||||
*.sqlite
|
*.sqlite
|
||||||
*.bak
|
*.bak
|
||||||
/bin
|
/bin
|
||||||
*.exe
|
*.exe
|
||||||
|
*secret*
|
||||||
|
mangaGetter
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
Value: secret,
|
Value: secret,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: 3600,
|
MaxAge: 3600,
|
||||||
Secure: true,
|
Secure: false,
|
||||||
HttpOnly: false,
|
HttpOnly: false,
|
||||||
SameSite: http.SameSiteLaxMode,
|
SameSite: http.SameSiteLaxMode,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ func (s *Server) RegisterRoutes() {
|
|||||||
s.mux.HandleFunc("/favicon.ico", s.HandleFavicon)
|
s.mux.HandleFunc("/favicon.ico", s.HandleFavicon)
|
||||||
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
|
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
|
||||||
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
|
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) StartTLS(port int, certFile, keyFile string) error {
|
func (s *Server) StartTLS(port int, certFile, keyFile string) error {
|
||||||
@@ -90,23 +89,25 @@ func (s *Server) Start(port int) error {
|
|||||||
return server.ListenAndServe()
|
return server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) RegisterUpdateMangas(interval time.Duration) {
|
func (s *Server) RegisterUpdater(interval time.Duration) {
|
||||||
for {
|
go func(s *Server) {
|
||||||
select {
|
for {
|
||||||
case <-time.After(interval):
|
select {
|
||||||
var all []*database.Manga
|
case <-time.After(interval):
|
||||||
s.DbMgr.Db.Find(&all)
|
var all []*database.Manga
|
||||||
for _, m := range all {
|
s.DbMgr.Db.Find(&all)
|
||||||
err, updated := s.UpdateLatestAvailableChapter(m)
|
for _, m := range all {
|
||||||
if err != nil {
|
err, updated := s.UpdateLatestAvailableChapter(m)
|
||||||
fmt.Println(err)
|
if err != nil {
|
||||||
}
|
fmt.Println(err)
|
||||||
if updated {
|
}
|
||||||
s.DbMgr.Db.Save(m)
|
if updated {
|
||||||
|
s.DbMgr.Db.Save(m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) LoadNext() {
|
func (s *Server) LoadNext() {
|
||||||
|
|||||||
7
main.go
7
main.go
@@ -25,6 +25,7 @@ var (
|
|||||||
databaseFlag = flag.String("database", "", "Path to sqlite.db file")
|
databaseFlag = flag.String("database", "", "Path to sqlite.db file")
|
||||||
certFlag = flag.String("cert", "", "Path to cert file, has to be used in conjunction with key")
|
certFlag = flag.String("cert", "", "Path to cert file, has to be used in conjunction with key")
|
||||||
keyFlag = flag.String("key", "", "Path to key file, has to be used in conjunction with cert")
|
keyFlag = flag.String("key", "", "Path to key file, has to be used in conjunction with cert")
|
||||||
|
updateIntervalFlag = flag.String("update", "1h", "Interval to update Mangas")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -84,7 +85,13 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interval, err := time.ParseDuration(*updateIntervalFlag)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
s.RegisterUpdater(interval)
|
||||||
s.RegisterRoutes()
|
s.RegisterRoutes()
|
||||||
|
|
||||||
if *certFlag != "" && *keyFlag != "" {
|
if *certFlag != "" && *keyFlag != "" {
|
||||||
err = s.StartTLS(*portFlag, *certFlag, *keyFlag)
|
err = s.StartTLS(*portFlag, *certFlag, *keyFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user