diff --git a/.gitignore b/.gitignore index ccf5f7b..d693441 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ findings.txt test.txt h.html -db.sqlite +*.sqlite +/bin +*.exe \ No newline at end of file diff --git a/Makefile b/Makefile index dfd2aca..5389829 100644 --- a/Makefile +++ b/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 \ No newline at end of file + GOOS=windows GOARCH=amd64 go build -o bin/MangaGetter-amd64_windows.exe ./cmd/mangaGetter/ \ No newline at end of file diff --git a/internal/database/chapter.go b/internal/database/chapter.go index e5ca4ee..034f8af 100644 --- a/internal/database/chapter.go +++ b/internal/database/chapter.go @@ -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 } diff --git a/internal/database/createDb.sql b/internal/database/createDb.sql index 78a9b77..798be11 100644 --- a/internal/database/createDb.sql +++ b/internal/database/createDb.sql @@ -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) ); diff --git a/internal/database/manga.go b/internal/database/manga.go index bbb2e7d..935d6a3 100644 --- a/internal/database/manga.go +++ b/internal/database/manga.go @@ -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 } diff --git a/internal/provider/bato.go b/internal/provider/bato.go index 7fc5db0..5cc14a4 100644 --- a/internal/provider/bato.go +++ b/internal/provider/bato.go @@ -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(`