use propper logger

This commit is contained in:
2026-01-09 17:44:45 +01:00
parent 42a1080981
commit d3c277eb7f
5 changed files with 52 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ package oplcli
import (
"fmt"
"io"
"log/slog"
"net/http"
"os"
"path"
@@ -38,12 +39,21 @@ func getArtUrlForGameFromGithub(gameID string) artUrls {
}
}
func downloadArtForGame(gameID string, targetDir string) error {
func downloadArtForGame(gameID string, targetDir string) {
urls := getArtUrlForGameFromGithub(gameID)
dl := func(url, kind string) (bool, error) {
return downloadFile(url, path.Join(targetDir, fmt.Sprintf("%s_%s.png", gameID, kind)))
totalDownloads := 0
dl := func(url, kind string) {
file := path.Join(targetDir, fmt.Sprintf("%s_%s.png", gameID, kind))
found, err := downloadFile(url, file)
if err != nil {
slog.Warn("Failed to download art file", "gameID", gameID, "url", url)
}
if found {
slog.Debug("Downloaded art file", "gameID", gameID, "kind", kind, "target", file)
totalDownloads++
}
}
dl(urls.cover, "COV")
@@ -54,7 +64,11 @@ func downloadArtForGame(gameID string, targetDir string) error {
dl(urls.screenshot2, "SRC2")
dl(urls.spine, "LAB")
return nil
if totalDownloads == 0 {
slog.Error("No art files found", "gameID", gameID)
} else {
slog.Info("Finished downloading art files", "gameID", gameID, "total", totalDownloads)
}
}
func downloadFile(url, target string) (bool, error) {