diff --git a/bato.go b/bato.go index 0a182f2..63066cc 100644 --- a/bato.go +++ b/bato.go @@ -25,7 +25,7 @@ func (b *Bato) GetImageList(html string) ([]string, error) { m := reg.FindStringSubmatch(html) if len(m) <= 0 { - return nil, &NoMoreError{Err: errors.New("no more content")} + return nil, errors.New("no more content") } match := m[1] diff --git a/go.mod b/go.mod index 832296c..31abf3c 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module mangaGetter go 1.22 -require github.com/mattn/go-sqlite3 v1.14.22 +require ( + github.com/mattn/go-sqlite3 v1.14.22 + golang.org/x/text v0.14.0 +) diff --git a/go.sum b/go.sum index e8d092a..81788cd 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/main.go b/main.go index 78a6488..cb0b8a6 100644 --- a/main.go +++ b/main.go @@ -9,14 +9,6 @@ import ( "sync" ) -type NoMoreError struct { - Err error -} - -func (e *NoMoreError) Error() string { - return e.Err.Error() -} - type Image struct { Path string Index int @@ -27,6 +19,17 @@ type ImageViewModel struct { Images []Image } +type MangaViewModel struct { + Title string + Number int + LastTime string + Url string +} + +type MenuViewModel struct { + Mangas []MangaViewModel +} + func main() { db := NewDatabase("db.sqlite", true) err := db.Open() @@ -34,22 +37,21 @@ func main() { return } - var latestTimeStamp int64 = 0 - var latestUrl string - for _, m := range db.Mangas { - if latestTimeStamp < m.LatestChapter.TimeStampUnix { - latestTimeStamp = m.LatestChapter.TimeStampUnix - latestUrl = m.LatestChapter.Url - } - } - - if latestUrl == "" { - latestUrl = "/title/80381-i-stan-the-prince/1539086-ch_16" - } + //var latestTimeStamp int64 = 0 + //var latestUrl string + //for _, m := range db.Mangas { + // if latestTimeStamp < m.LatestChapter.TimeStampUnix { + // latestTimeStamp = m.LatestChapter.TimeStampUnix + // latestUrl = m.LatestChapter.Url + // } + //} + // + //if latestUrl == "" { + // latestUrl = "/title/80381-i-stan-the-prince/1539086-ch_16" + //} server := Server{ ImageBuffers: make(map[string]*bytes.Buffer), - CurrSubUrl: latestUrl, NextReady: make(chan bool), PrevReady: make(chan bool), Provider: &Bato{}, @@ -66,18 +68,17 @@ func main() { } }() - server.LoadCurr() - go server.LoadPrev() - go server.LoadNext() + //server.LoadCurr() + //go server.LoadPrev() + //go server.LoadNext() - http.HandleFunc("/", server.HandleCurrent) + http.HandleFunc("/", server.HandleMenu) + http.HandleFunc("/new/title/{title}/{chapter}", server.HandleNew) + http.HandleFunc("/current/", server.HandleCurrent) http.HandleFunc("/img/{url}/", server.HandleImage) http.HandleFunc("POST /next", server.HandleNext) http.HandleFunc("POST /prev", server.HandlePrev) - http.HandleFunc("POST /exit", func(_ http.ResponseWriter, _ *http.Request) { - Close(&db) - }) - http.HandleFunc("/new/{title}/{chapter}", server.HandleNew) + http.HandleFunc("POST /exit", server.HandleExit) fmt.Println("Server starting...") err = http.ListenAndServe(":8000", nil) diff --git a/menu.gohtml b/menu.gohtml new file mode 100644 index 0000000..bb7fe7a --- /dev/null +++ b/menu.gohtml @@ -0,0 +1,21 @@ + + +
+ +