diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2021-03-04 19:44:02 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2021-03-04 19:48:27 -0500 |
| commit | b9bb17044a8c2b47c7e96660e27ab645f82bec9d (patch) | |
| tree | 6c5bff2c5eaaebfc1ce9b01119308dcc39a75253 /cmd/web/app.go | |
| parent | 3b6f5647b0689abf04be73c3cf00297051753435 (diff) | |
| download | steam-export-b9bb17044a8c2b47c7e96660e27ab645f82bec9d.tar.gz steam-export-b9bb17044a8c2b47c7e96660e27ab645f82bec9d.tar.xz | |
Further refactoring.
Diffstat (limited to 'cmd/web/app.go')
| -rw-r--r-- | cmd/web/app.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/cmd/web/app.go b/cmd/web/app.go new file mode 100644 index 0000000..8f6df89 --- /dev/null +++ b/cmd/web/app.go @@ -0,0 +1,75 @@ +package main + +import ( + "sync" + "html/template" + "time" + + "riedstra.dev/mitch/steam-export/steam" +) + +type steamLib struct { + steam.Library + sync.Mutex +} + +type statusInfo struct { + sync.RWMutex + Running bool + Error error + Url string + Transferred int64 + Size int64 + Start *time.Time +} + + +type App struct { + Library *steamLib + Status *statusInfo + + Templates *template.Template + + // Sending to this channel triggers the downloader in the background + download chan string +} + +func NewApp(libPath string) (*App, error) { + lib, err := steam.NewLibrary(libPath) + if err != nil { + return nil, err + } + + a := &App{ + Library: &steamLib{}, + Status: &statusInfo{}, + download: make(chan string), + } + + a.Library.Library = *lib + + a.Templates = template.Must(template.New("index").Parse(indexTemplate)) + + return a, nil +} + +func (a *App) LibrarySet(path string) { + Logger.Println("Starting library reload") + a.Library.Lock() + defer a.Library.Unlock() + var err error + l2, err := steam.NewLibrary(path) + if err != nil { + Logger.Printf("Error reopening lib: %s", err) + return + } + a.Library.Library = *l2 + Logger.Println("Done reloading lib") +} + +func (a *App) LibraryReload() { + cur := a.Library.Folder + a.LibrarySet(cur) + return +} + |
