Added different Ports for release and develop, changed out Sort for simple iteration (Should be faster), Fixed Theme Switcher, fixed Saving of read chapters

This commit is contained in:
Pablu23
2024-04-02 19:27:25 +02:00
parent e3e0da86fc
commit f712211194
6 changed files with 18 additions and 12 deletions

View File

@@ -2,6 +2,8 @@
package main package main
const port = 8080
func getDbPath() string { func getDbPath() string {
return "db.sqlite" return "db.sqlite"
} }

View File

@@ -33,8 +33,6 @@ func main() {
} }
}() }()
port := 8080
go func() { go func() {
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)
err := open(fmt.Sprintf("http://localhost:%d", port)) err := open(fmt.Sprintf("http://localhost:%d", port))

View File

@@ -7,6 +7,8 @@ import (
"path/filepath" "path/filepath"
) )
const port = 8000
func getDbPath() string { func getDbPath() string {
dir, err := os.UserCacheDir() dir, err := os.UserCacheDir()
if err != nil { if err != nil {

View File

@@ -2,9 +2,7 @@ package database
import ( import (
"bytes" "bytes"
"cmp"
"database/sql" "database/sql"
"slices"
) )
type Manga struct { type Manga struct {
@@ -27,19 +25,22 @@ func NewManga(id int, title string, timeStampUnix int64) Manga {
func (m *Manga) GetLatestChapter(chapters *DbTable[int, Chapter]) (*Chapter, bool) { func (m *Manga) GetLatestChapter(chapters *DbTable[int, Chapter]) (*Chapter, bool) {
c := chapters.All() c := chapters.All()
slices.SortStableFunc(c, func(a, b Chapter) int { highest := int64(0)
return cmp.Compare(b.TimeStampUnix, a.TimeStampUnix) index := 0
}) for i, chapter := range c {
if chapter.MangaId == m.Id && highest < chapter.TimeStampUnix {
for _, chapter := range c { highest = chapter.TimeStampUnix
if chapter.MangaId == m.Id { index = i
return &chapter, true
} }
} }
if highest == 0 {
return nil, false return nil, false
} }
return &c[index], true
}
func updateManga(db *sql.DB, m *Manga) error { func updateManga(db *sql.DB, m *Manga) error {
const cmd = "UPDATE Manga set Title = ?, TimeStampUnixEpoch = ?, Thumbnail = ?, LatestAvailableChapter = ? WHERE ID = ?" 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) _, err := db.Exec(cmd, m.Title, m.TimeStampUnix, m.Thumbnail.Bytes(), m.LastChapterNum, m.Id)

View File

@@ -117,12 +117,14 @@ func (d *DbTable[K, T]) Save(db *sql.DB) error {
if err != nil { if err != nil {
return err return err
} }
d.updated[k] = Loaded
} else { } else {
item := d.items[k] item := d.items[k]
err := d.insertFunc(db, &item) err := d.insertFunc(db, &item)
if err != nil { if err != nil {
return err return err
} }
d.updated[k] = Loaded
} }
} }
return nil return nil

View File

@@ -138,6 +138,7 @@
<form method="post" action="/setting/"> <form method="post" action="/setting/">
<label for="theme">Theme</label> <label for="theme">Theme</label>
<select onchange="this.form.submit()" id="theme" name="theme"> <select onchange="this.form.submit()" id="theme" name="theme">
<option value="" selected disabled hidden>Choose Theme</option>
<option value="white">White</option> <option value="white">White</option>
<option value="dark">Dark</option> <option value="dark">Dark</option>
</select> </select>