added local state to cache uploads

This commit is contained in:
2025-11-08 23:33:40 +01:00
parent 4d772878bc
commit 15b87e8c36
2 changed files with 69 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package steamimmich
import (
"fmt"
"log"
"slices"
)
type Config struct {
@@ -28,6 +29,11 @@ func Run(config Config) {
immichClient := newImmichHttpClient(config.APIKey)
localState, err := loadLocalState("./state.json")
if err != nil {
log.Fatalf("Failed to load local state: %s", err)
}
gameNameCache := make(map[string]string)
for appid, files := range screenshotFiles {
@@ -35,6 +41,14 @@ func Run(config Config) {
assetsInGame := make([]string, 0)
for _, filepath := range files {
idx := slices.IndexFunc(localState.Assets, func(e AssetState) bool { return e.FilePath == filepath })
if idx != -1 {
log.Printf("Asset already uploaded: %s", filepath)
continue
}
res, err := uploadToImmich(filepath, appid, config.BaseURL, config.DeiveID, &immichClient)
if err != nil {
@@ -44,7 +58,7 @@ func Run(config Config) {
log.Printf("Assest uploaded: %s (%s) %s with ID: %s", gameName, appid, filepath, res.ID)
return
localState.Assets = append(localState.Assets, AssetState{FilePath: filepath, ImmichID: res.ID})
assetsInGame = append(assetsInGame, res.ID)
}
@@ -67,4 +81,9 @@ func Run(config Config) {
}
log.Println("Finished uploading screenshots")
err = saveLocalState("./state.json", *localState)
if err != nil {
log.Fatalf("Failed to save local cache: %s", err)
return
}
}