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
const port = 8080
func getDbPath() string {
return "db.sqlite"
}

View File

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

View File

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

View File

@@ -2,9 +2,7 @@ package database
import (
"bytes"
"cmp"
"database/sql"
"slices"
)
type Manga struct {
@@ -27,17 +25,20 @@ func NewManga(id int, title string, timeStampUnix int64) Manga {
func (m *Manga) GetLatestChapter(chapters *DbTable[int, Chapter]) (*Chapter, bool) {
c := chapters.All()
slices.SortStableFunc(c, func(a, b Chapter) int {
return cmp.Compare(b.TimeStampUnix, a.TimeStampUnix)
})
for _, chapter := range c {
if chapter.MangaId == m.Id {
return &chapter, true
highest := int64(0)
index := 0
for i, chapter := range c {
if chapter.MangaId == m.Id && highest < chapter.TimeStampUnix {
highest = chapter.TimeStampUnix
index = i
}
}
return nil, false
if highest == 0 {
return nil, false
}
return &c[index], true
}
func updateManga(db *sql.DB, m *Manga) error {

View File

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

View File

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