diff --git a/appview/state/repo.go b/appview/state/repo.go index 9474f798..f72b2443 100644 --- a/appview/state/repo.go +++ b/appview/state/repo.go @@ -54,26 +54,12 @@ func (s *State) RepoIndex(w http.ResponseWriter, r *http.Request) { return } - resp, err := us.Index(f.OwnerDid(), f.RepoName, ref) + result, err := us.Index(f.OwnerDid(), f.RepoName, ref) if err != nil { s.pages.Error503(w) log.Println("failed to reach knotserver", err) return } - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - if err != nil { - log.Printf("Error reading response body: %v", err) - return - } - - var result types.RepoIndexResponse - err = json.Unmarshal(body, &result) - if err != nil { - log.Printf("Error unmarshalling response body: %v", err) - return - } tagMap := make(map[string][]string) for _, tag := range result.Tags { @@ -155,7 +141,7 @@ func (s *State) RepoIndex(w http.ResponseWriter, r *http.Request) { LoggedInUser: user, RepoInfo: repoInfo, TagMap: tagMap, - RepoIndexResponse: result, + RepoIndexResponse: *result, CommitsTrunc: commitsTrunc, TagsTrunc: tagsTrunc, ForkInfo: forkInfo, diff --git a/knotclient/signer.go b/knotclient/signer.go index 9098ad1e..46038e57 100644 --- a/knotclient/signer.go +++ b/knotclient/signer.go @@ -7,6 +7,8 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io" + "log" "net/http" "net/url" "time" diff --git a/knotclient/unsigned.go b/knotclient/unsigned.go index 16bca3f7..976591bd 100644 --- a/knotclient/unsigned.go +++ b/knotclient/unsigned.go @@ -75,7 +75,7 @@ func do[T any](us *UnsignedClient, req *http.Request) (*T, error) { return &result, nil } -func (us *UnsignedClient) Index(ownerDid, repoName, ref string) (*http.Response, error) { +func (us *UnsignedClient) Index(ownerDid, repoName, ref string) (*types.RepoIndexResponse, error) { const ( Method = "GET" ) @@ -90,7 +90,7 @@ func (us *UnsignedClient) Index(ownerDid, repoName, ref string) (*http.Response, return nil, err } - return us.client.Do(req) + return do[types.RepoIndexResponse](us, req) } func (us *UnsignedClient) Log(ownerDid, repoName, ref string, page int) (*http.Response, error) {