Compare commits
2 Commits
6e46f52b52
...
c0eae078fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
c0eae078fa
|
|||
|
bc862a41ad
|
@@ -1,29 +1,91 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
steamimmich "git.kapelle.org/niklas/steam-immich/internal"
|
steamimmich "git.kapelle.org/niklas/steam-immich/internal"
|
||||||
"github.com/alexflint/go-arg"
|
"github.com/alexflint/go-arg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
BaseURL string `arg:"--base-url,required,env:BASE_URL" placeholder:"https://demo.immich.app"`
|
BaseURL string `arg:"--base-url,required" placeholder:"BASE_URL" help:"Base URL of the Immich instance e.g.: https://demo.immich.app"`
|
||||||
APIKey string `arg:"--api-key,required,env:API_KEY" placeholder:"API_KEY"`
|
APIKey string `arg:"--api-key,required" placeholder:"API_KEY" help:"API Key. Needs asset.upload, asset.update, albumAsset.create"`
|
||||||
UserdataDir string `arg:"--steam-userdata-dir,env:USERDATA_DIR" default:"$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam/userdata"`
|
UserdataDir string `arg:"--steam-userdata-dir" placeholder:"USERDATA_DIR" help:"Steam userdata directory. If not set, search automaticly."`
|
||||||
DeviceID string `arg:"--device-id,env:DEVICE_ID" default:"steam-immich"`
|
DeviceID string `arg:"--device-id" default:"steam-immich" help:"Device ID of the uploads"`
|
||||||
Album string `arg:"--album,env:ALBUM"`
|
Album string `arg:"--album" help:"UUID of a album to upload to"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var args args
|
var args args
|
||||||
arg.MustParse(&args)
|
arg.MustParse(&args)
|
||||||
|
|
||||||
|
var steamUserdataDir = ""
|
||||||
|
|
||||||
|
if args.UserdataDir != "" {
|
||||||
|
steamUserdataDir = os.ExpandEnv(args.UserdataDir)
|
||||||
|
} else {
|
||||||
|
steamUserdataDir = findUserdataDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
if steamUserdataDir == "" {
|
||||||
|
log.Fatal("Can not find steam userdata dir. Please set with --steam-userdata-dir")
|
||||||
|
}
|
||||||
|
|
||||||
steamimmich.Run(steamimmich.Config{
|
steamimmich.Run(steamimmich.Config{
|
||||||
APIKey: args.APIKey,
|
APIKey: args.APIKey,
|
||||||
BaseURL: args.BaseURL,
|
BaseURL: args.BaseURL,
|
||||||
UserdataDir: os.ExpandEnv(args.UserdataDir),
|
UserdataDir: steamUserdataDir,
|
||||||
DeiveID: args.DeviceID,
|
DeiveID: args.DeviceID,
|
||||||
Album: args.Album,
|
Album: args.Album,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findUserdataDir() string {
|
||||||
|
var candidates []string
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
// Common Steam install paths on Windows
|
||||||
|
localAppData := os.Getenv("LOCALAPPDATA")
|
||||||
|
programFiles := os.Getenv("ProgramFiles(x86)")
|
||||||
|
if programFiles == "" {
|
||||||
|
programFiles = os.Getenv("ProgramFiles")
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates = []string{
|
||||||
|
filepath.Join(programFiles, "Steam"),
|
||||||
|
filepath.Join(localAppData, "Steam"),
|
||||||
|
}
|
||||||
|
|
||||||
|
case "linux":
|
||||||
|
home := os.Getenv("HOME")
|
||||||
|
|
||||||
|
candidates = []string{
|
||||||
|
filepath.Join(home, ".steam", "steam"), // standard
|
||||||
|
filepath.Join(home, ".local", "share", "Steam"), // alternate
|
||||||
|
filepath.Join(home, ".var", "app", "com.valvesoftware.Steam", "data", "Steam"), // Flatpak
|
||||||
|
}
|
||||||
|
case "darwin":
|
||||||
|
// Common Steam install path on macOS
|
||||||
|
home := os.Getenv("HOME")
|
||||||
|
candidates = []string{
|
||||||
|
filepath.Join(home, "Library", "Application Support", "Steam"),
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, base := range candidates {
|
||||||
|
userdata := filepath.Join(base, "userdata")
|
||||||
|
info, err := os.Stat(userdata)
|
||||||
|
if err == nil && info.IsDir() {
|
||||||
|
return userdata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user