Skip to content

Commit

Permalink
Allow using an http ipfs gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed Oct 9, 2024
1 parent a5b048a commit fddec51
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,18 @@ func downloadIPFS(ctx context.Context, localPath, url, description string, expec
logrus.Debugf("downloading %q into %q", url, localPath)

address := strings.Replace(url, "ipfs://", "", 1)

// Possibly use an ipfs getway such as "https://ipfs.io" or "http://127.0.0.1:8080"
if gateway := os.Getenv("IPFS_GATEWAY"); gateway != "" {
if strings.HasPrefix(gateway, "http") {
url = fmt.Sprintf("%s/ipfs/%s", gateway, address)
return downloadHTTP(ctx, localPath, "", "", url, description, expectedDigest)
}
return fmt.Errorf("unknown gateway: %q", gateway)
}

address = strings.Split(address, "/")[0] // remove file name from path

cmd := exec.CommandContext(ctx, "ipfs", "ls", address)
cmd.Stderr = os.Stderr
out, err := cmd.Output()
Expand Down

0 comments on commit fddec51

Please sign in to comment.