Skip to content

Commit

Permalink
clients/ipfs: Use CIDv1 for all IPFS uploads (#35)
Browse files Browse the repository at this point in the history
It is the recommended approach for CIDs as it's
future-proof (hash alg is embedded in the CID)
and also because it's case insensitive and will
work better on all scenarios (like URLs).

It is weirdly not the default on Piñata yet, but
while it is not we can easily toggle it on our
export requests.

It does not break compatibility on anything that I can
think of.

Reference: https://docs.ipfs.io/how-to/best-practices-for-ipfs-builders/
  • Loading branch information
victorges authored May 26, 2022
1 parent d6fdaae commit ab3deae
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clients/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"context"
"encoding/json"
"io"
"strings"
"time"

"github.com/golang/glog"
)

const (
pinataBaseUrl = "https://api.pinata.cloud"
jsonMimeType = "application/json"
pinataOptions = `{"cidVersion":1}`
)

type IPFS interface {
Expand Down Expand Up @@ -59,9 +62,10 @@ type uploadResponse struct {
func (p *pinataClient) PinContent(ctx context.Context, filename, fileContentType string, data io.Reader) (string, interface{}, error) {
parts := []part{
{"file", filename, fileContentType, data},
{"pinataOptions", "", jsonMimeType, strings.NewReader(pinataOptions)},
}
if p.filesMetadata != nil {
parts = append(parts, part{"pinataMetadata", "", "application/json", bytes.NewReader(p.filesMetadata)})
parts = append(parts, part{"pinataMetadata", "", jsonMimeType, bytes.NewReader(p.filesMetadata)})
}
body, contentType := multipartBody(parts)
defer body.Close()
Expand Down

0 comments on commit ab3deae

Please sign in to comment.