Added interval flag

This commit is contained in:
Pablu23
2024-05-30 20:30:45 +02:00
parent e9c7c6f915
commit 8de5bb0fdc
4 changed files with 27 additions and 17 deletions

4
.gitignore vendored
View File

@@ -5,4 +5,6 @@ h.html
*.sqlite
*.bak
/bin
*.exe
*.exe
*secret*
mangaGetter

View File

@@ -26,7 +26,7 @@ func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) {
Value: secret,
Path: "/",
MaxAge: 3600,
Secure: true,
Secure: false,
HttpOnly: false,
SameSite: http.SameSiteLaxMode,
})

View File

@@ -67,7 +67,6 @@ func (s *Server) RegisterRoutes() {
s.mux.HandleFunc("/favicon.ico", s.HandleFavicon)
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
}
func (s *Server) StartTLS(port int, certFile, keyFile string) error {
@@ -90,23 +89,25 @@ func (s *Server) Start(port int) error {
return server.ListenAndServe()
}
func (s *Server) RegisterUpdateMangas(interval time.Duration) {
for {
select {
case <-time.After(interval):
var all []*database.Manga
s.DbMgr.Db.Find(&all)
for _, m := range all {
err, updated := s.UpdateLatestAvailableChapter(m)
if err != nil {
fmt.Println(err)
}
if updated {
s.DbMgr.Db.Save(m)
func (s *Server) RegisterUpdater(interval time.Duration) {
go func(s *Server) {
for {
select {
case <-time.After(interval):
var all []*database.Manga
s.DbMgr.Db.Find(&all)
for _, m := range all {
err, updated := s.UpdateLatestAvailableChapter(m)
if err != nil {
fmt.Println(err)
}
if updated {
s.DbMgr.Db.Save(m)
}
}
}
}
}
}(s)
}
func (s *Server) LoadNext() {

View File

@@ -25,6 +25,7 @@ var (
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")
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() {
@@ -84,7 +85,13 @@ func main() {
}()
}
interval, err := time.ParseDuration(*updateIntervalFlag)
if err != nil {
panic(err)
}
s.RegisterUpdater(interval)
s.RegisterRoutes()
if *certFlag != "" && *keyFlag != "" {
err = s.StartTLS(*portFlag, *certFlag, *keyFlag)
if err != nil {