Fixed various Bugs
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,4 +2,6 @@
|
||||
findings.txt
|
||||
test.txt
|
||||
h.html
|
||||
db.sqlite
|
||||
*.sqlite
|
||||
/bin
|
||||
*.exe
|
||||
6
Makefile
6
Makefile
@@ -2,10 +2,10 @@ run: develop
|
||||
bin/develop
|
||||
|
||||
develop:
|
||||
go build -tags Develop -o bin/develop cmd/mangaGetter/main.go
|
||||
go build -tags Develop -o bin/develop ./cmd/mangaGetter/
|
||||
|
||||
release:
|
||||
go build -o bin/MangaGetter_unix cmd/mangaGetter/main.go
|
||||
go build -o bin/MangaGetter_unix ./cmd/mangaGetter/
|
||||
|
||||
win-amd64:
|
||||
GOOS=windows GOARCH=amd64 go build -o bin/MangaGetter-amd64_windows.exe cmd/mangaGetter/main.go
|
||||
GOOS=windows GOARCH=amd64 go build -o bin/MangaGetter-amd64_windows.exe ./cmd/mangaGetter/
|
||||
@@ -9,11 +9,11 @@ type Chapter struct {
|
||||
MangaId int
|
||||
Url string
|
||||
Name string
|
||||
Number int
|
||||
Number string
|
||||
TimeStampUnix int64
|
||||
}
|
||||
|
||||
func NewChapter(id int, mangaId int, url string, name string, number int, timeStampUnix int64) Chapter {
|
||||
func NewChapter(id int, mangaId int, url string, name string, number string, timeStampUnix int64) Chapter {
|
||||
return Chapter{
|
||||
Id: id,
|
||||
MangaId: mangaId,
|
||||
@@ -52,6 +52,6 @@ func loadChapters(db *sql.DB) (map[int]Chapter, error) {
|
||||
}
|
||||
|
||||
func deleteChapter(db *sql.DB, key int) error {
|
||||
_, err := db.Exec("DELETE from Manga where ID = ?", key)
|
||||
_, err := db.Exec("DELETE from Chapter where ID = ?", key)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ create table if not exists Manga (
|
||||
ID integer not null primary key,
|
||||
Title text,
|
||||
TimeStampUnixEpoch integer not null,
|
||||
Thumbnail blob,
|
||||
LatestAvailableChapter integer not null
|
||||
Thumbnail blob null,
|
||||
LatestAvailableChapter text
|
||||
);
|
||||
|
||||
create table if not exists Chapter (
|
||||
@@ -11,7 +11,7 @@ create table if not exists Chapter (
|
||||
MangaID integer not null,
|
||||
Url text not null,
|
||||
Name text null,
|
||||
Number integer not null,
|
||||
Number text null,
|
||||
TimeStampUnixEpoch integer not null,
|
||||
foreign key(MangaID) references Manga(ID)
|
||||
);
|
||||
|
||||
@@ -10,14 +10,15 @@ type Manga struct {
|
||||
Title string
|
||||
TimeStampUnix int64
|
||||
Thumbnail *bytes.Buffer
|
||||
LastChapterNum int
|
||||
LastChapterNum string
|
||||
}
|
||||
|
||||
func NewManga(id int, title string, timeStampUnix int64) Manga {
|
||||
return Manga{
|
||||
Id: id,
|
||||
Title: title,
|
||||
TimeStampUnix: timeStampUnix,
|
||||
Id: id,
|
||||
Title: title,
|
||||
TimeStampUnix: timeStampUnix,
|
||||
LastChapterNum: "",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,13 +44,25 @@ func (m *Manga) GetLatestChapter(chapters *DbTable[int, Chapter]) (*Chapter, boo
|
||||
|
||||
func updateManga(db *sql.DB, m *Manga) error {
|
||||
const cmd = "UPDATE Manga set Title = ?, TimeStampUnixEpoch = ?, Thumbnail = ?, LatestAvailableChapter = ? WHERE ID = ?"
|
||||
_, err := db.Exec(cmd, m.Title, m.TimeStampUnix, m.Thumbnail.Bytes(), m.LastChapterNum, m.Id)
|
||||
var err error
|
||||
if m.Thumbnail == nil {
|
||||
_, err = db.Exec(cmd, m.Title, m.TimeStampUnix, nil, m.LastChapterNum, m.Id)
|
||||
|
||||
} else {
|
||||
_, err = db.Exec(cmd, m.Title, m.TimeStampUnix, m.Thumbnail.Bytes(), m.LastChapterNum, m.Id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func insertManga(db *sql.DB, manga *Manga) error {
|
||||
const cmd = "INSERT INTO Manga(ID, Title, TimeStampUnixEpoch, Thumbnail, LatestAvailableChapter) values(?, ?, ?, ?, ?)"
|
||||
_, err := db.Exec(cmd, manga.Id, manga.Title, manga.TimeStampUnix, manga.Thumbnail.Bytes(), manga.LastChapterNum)
|
||||
var err error
|
||||
if manga.Thumbnail == nil {
|
||||
_, err = db.Exec(cmd, manga.Id, manga.Title, manga.TimeStampUnix, nil, manga.LastChapterNum)
|
||||
|
||||
} else {
|
||||
_, err = db.Exec(cmd, manga.Id, manga.Title, manga.TimeStampUnix, manga.Thumbnail.Bytes(), manga.LastChapterNum)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,6 +91,6 @@ func loadMangas(db *sql.DB) (map[int]Manga, error) {
|
||||
}
|
||||
|
||||
func deleteManga(db *sql.DB, key int) error {
|
||||
_, err := db.Exec("DELETE from Chapter where ID = ?", key)
|
||||
_, err := db.Exec("DELETE from Manga where ID = ?", key)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func (b *Bato) GetTitleIdAndChapterId(url string) (titleId int, chapterId int, e
|
||||
}
|
||||
|
||||
func (b *Bato) GetChapterList(subUrl string) (subUrls []string, err error) {
|
||||
reg, err := regexp.Compile(`<div class="space-x-1">.*?<a href="(.*?)" .*?>Chapter (\d*)</a>`)
|
||||
reg, err := regexp.Compile(`<div class="space-x-1">.*?<a href="(.*?)" .*?>.*?</a>`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
||||
|
||||
// This is very slow
|
||||
// TODO: put this into own Method
|
||||
if manga.LastChapterNum == 0 {
|
||||
if manga.LastChapterNum == "" {
|
||||
err, updated := s.UpdateLatestAvailableChapter(&manga)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -173,6 +173,7 @@ func (s *Server) HandleExit(w http.ResponseWriter, r *http.Request) {
|
||||
err := s.DbMgr.Save()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
http.Redirect(w, r, "/curr", http.StatusTemporaryRedirect)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -207,37 +208,31 @@ func (s *Server) HandleCurrent(w http.ResponseWriter, _ *http.Request) {
|
||||
mangaId, chapterId, err := s.Provider.GetTitleIdAndChapterId(s.CurrSubUrl)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
title, chapterName, err := s.Provider.GetTitleAndChapter(s.CurrSubUrl)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
manga, ok := s.DbMgr.Mangas.Get(mangaId)
|
||||
if !ok {
|
||||
manga = database.NewManga(mangaId, title, time.Now().Unix())
|
||||
} else {
|
||||
manga.TimeStampUnix = time.Now().Unix()
|
||||
}
|
||||
|
||||
chapter, ok := s.DbMgr.Chapters.Get(chapterId)
|
||||
if !ok {
|
||||
chapterNumberStr := strings.Replace(chapterName, "ch_", "", 1)
|
||||
number, err := strconv.Atoi(chapterNumberStr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
number = 0
|
||||
}
|
||||
|
||||
chapter = database.NewChapter(chapterId, manga.Id, s.CurrSubUrl, chapterName, number, time.Now().Unix())
|
||||
} else {
|
||||
chapter.TimeStampUnix = time.Now().Unix()
|
||||
}
|
||||
|
||||
s.DbMgr.Chapters.Set(chapterId, chapter)
|
||||
s.DbMgr.Mangas.Set(mangaId, manga)
|
||||
}
|
||||
}
|
||||
|
||||
title, chapterName, err := s.Provider.GetTitleAndChapter(s.CurrSubUrl)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
manga, ok := s.DbMgr.Mangas.Get(mangaId)
|
||||
if !ok {
|
||||
manga = database.NewManga(mangaId, title, time.Now().Unix())
|
||||
} else {
|
||||
manga.TimeStampUnix = time.Now().Unix()
|
||||
}
|
||||
|
||||
chapter, ok := s.DbMgr.Chapters.Get(chapterId)
|
||||
if !ok {
|
||||
chapterNumberStr := strings.Replace(chapterName, "ch_", "", 1)
|
||||
chapter = database.NewChapter(chapterId, manga.Id, s.CurrSubUrl, chapterName, chapterNumberStr, time.Now().Unix())
|
||||
} else {
|
||||
chapter.TimeStampUnix = time.Now().Unix()
|
||||
}
|
||||
|
||||
s.DbMgr.Chapters.Set(chapterId, chapter)
|
||||
s.DbMgr.Mangas.Set(mangaId, manga)
|
||||
|
||||
err = tmpl.Execute(w, s.CurrViewModel)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
@@ -223,15 +223,10 @@ func (s *Server) UpdateLatestAvailableChapter(manga *database.Manga) (error, boo
|
||||
|
||||
chapterNumberStr := strings.Replace(c, "ch_", "", 1)
|
||||
|
||||
i, err := strconv.Atoi(chapterNumberStr)
|
||||
if err != nil {
|
||||
return err, false
|
||||
}
|
||||
|
||||
if manga.LastChapterNum == i {
|
||||
if manga.LastChapterNum == chapterNumberStr {
|
||||
return nil, false
|
||||
} else {
|
||||
manga.LastChapterNum = i
|
||||
manga.LastChapterNum = chapterNumberStr
|
||||
return nil, true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ type ImageViewModel struct {
|
||||
type MangaViewModel struct {
|
||||
ID int
|
||||
Title string
|
||||
Number int
|
||||
LastNumber int
|
||||
Number string
|
||||
LastNumber string
|
||||
LastTime string
|
||||
Url string
|
||||
ThumbnailUrl string
|
||||
|
||||
Reference in New Issue
Block a user