Skip to content

Commit

Permalink
reduce dup code and user flixkit's get flix file given a url
Browse files Browse the repository at this point in the history
  • Loading branch information
bthaile committed Nov 20, 2023
1 parent 742416d commit 231038a
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions internal/super/flix.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -319,22 +317,11 @@ func getTemplate(state *flowkit.State, flixService flixkit.FlixService, flixQuer
return nil, fmt.Errorf("could not parse flix from file %s: %w", flixQuery, err)
}
case flixUrl:
resp, err := http.Get(flixQuery)
flixString, err := flixkit.FetchFlixWithContext(ctx, flixQuery)
if err != nil {
return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("server returned non-200 status code %w", resp.StatusCode)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

template, err = flixkit.ParseFlix(string(body))
template, err = flixkit.ParseFlix(flixString)
if err != nil {
return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err)
}
Expand Down

0 comments on commit 231038a

Please sign in to comment.