diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2021-08-04 23:53:36 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2021-08-04 23:53:36 -0400 |
| commit | c202f2eca32e1ab2e313417168351df1c58ee062 (patch) | |
| tree | 6540629b337d2d769581baec26096ac0555f71f9 /steam/extract_http.go | |
| parent | 742938b00222c7ad57ad11eb24850d9202c2503d (diff) | |
| download | steam-export-c202f2eca32e1ab2e313417168351df1c58ee062.tar.gz steam-export-c202f2eca32e1ab2e313417168351df1c58ee062.tar.xz | |
More major changes. Web UI works. Downloading games works. Status works. extractFile needs work
Diffstat (limited to 'steam/extract_http.go')
| -rw-r--r-- | steam/extract_http.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/steam/extract_http.go b/steam/extract_http.go new file mode 100644 index 0000000..6884bee --- /dev/null +++ b/steam/extract_http.go @@ -0,0 +1,34 @@ +package steam + +import ( + "fmt" + "net/http" + "strconv" +) + +// ExtractHTTP is a wrapper around Extract that handles an HTTP endpoint. +// this spawns an "extractHTTP" on the library. Status will be updated there +// as this goes along. Non fatal and fatal errors will be populated there +func (l *Library) ExtractHTTP(url string) (*Game, error) { + g := &Game{} + j := newJob("extractHTTP", g) + defer j.done() + + l.status.addJob(j) + + resp, err := http.Get(url) + if err != nil { + j.addError(err) + return g, err + } + + estSize, err := strconv.ParseInt(resp.Header.Get("Estimated-size"), 10, 64) + if err != nil { + j.addError(err) + return g, fmt.Errorf("Failed to convert estimated size header: %w", err) + } + + j.setSize(estSize) + + return l.extractUpdate(j, g, resp.Body) +} |
