Replaced the gin framwwork with echo

This commit is contained in:
2025-01-13 11:57:48 +01:00
parent 8e2d22b899
commit 034ba35fbb
32 changed files with 348 additions and 266 deletions

View File

@@ -1,34 +0,0 @@
package server
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Host string
Port int
User string
Password string
Dbname string
Path string
}
var Conf *Config
func ReadConf(filename string) error {
buf, err := os.ReadFile(filename)
if err != nil {
return err
}
c := &Config{}
err = yaml.Unmarshal(buf, c)
if err != nil {
return fmt.Errorf("in file %q: %w", filename, err)
}
Conf = c
return err
}

View File

@@ -260,15 +260,30 @@ func checkBrokenSongs() {
}
db.RemoveBrokenSongs(brokenSongs)
}
func SyncGamesNewFull() Response {
return syncGamesNew(true)
}
func SyncGamesNew() Response {
func SyncGamesNewOnlyChanges() Response {
return syncGamesNew(false)
}
func syncGamesNew(full bool) Response {
musicPath := os.Getenv("MUSIC_PATH")
fmt.Printf("dir: %s\n", musicPath)
repo = repository.New(db.Dbpool)
start := time.Now()
fmt.Printf("dir: %s\n", Conf.Path)
foldersToSkip := []string{".sync", "dist", "old"}
fmt.Println(foldersToSkip)
var err error
gamesAdded = nil
gamesReAdded = nil
gamesChangedTitle = nil
gamesChangedContent = nil
gamesRemoved = nil
catchedErrors = nil
brokenSongs = nil
gamesBeforeSync, err = repo.FindAllGames(db.Ctx)
handleError("FindAllGames Before", err, "")
@@ -279,7 +294,7 @@ func SyncGamesNew() Response {
err = repo.SetGameDeletionDate(db.Ctx)
handleError("SetGameDeletionDate", err, "")
directories, err := os.ReadDir(Conf.Path)
directories, err := os.ReadDir(musicPath)
if err != nil {
log.Fatal(err)
}
@@ -288,7 +303,7 @@ func SyncGamesNew() Response {
for _, dir := range directories {
go func() {
defer syncWg.Done()
syncGameNew(dir, foldersToSkip, Conf.Path)
syncGameNew(dir, foldersToSkip, musicPath, full)
}()
}
syncWg.Wait()
@@ -339,7 +354,7 @@ func SyncGamesNew() Response {
for _, game := range gamesRemovedTemp {
var found bool = false
for key, _ := range gamesChangedTitle {
for key := range gamesChangedTitle {
if game == key {
found = true
//fmt.Printf("Game: %s, Found: %v break2\n", game, found)
@@ -408,7 +423,7 @@ func checkBrokenSongNew(song repository.Song) {
}
}
func syncGameNew(file os.DirEntry, foldersToSkip []string, baseDir string) {
func syncGameNew(file os.DirEntry, foldersToSkip []string, baseDir string, full bool) {
if file.IsDir() && !contains(foldersToSkip, file.Name()) {
gameDir := baseDir + file.Name() + "/"
@@ -441,6 +456,9 @@ func syncGameNew(file os.DirEntry, foldersToSkip []string, baseDir string) {
}
}
if full {
status = TitleChanged
}
entries, err := os.ReadDir(gameDir)
if err != nil {
log.Println(err)