mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
fix: interop with 'block put' from go-ipfs 0.13 (#158)
* chore: interop with go-ipfs 0.13 Applies necessary changes to ensure 'block/put' works and is backward-compatible. Context: https://github.com/ipfs/go-ipfs/pull/8568 * chore: 0.3.1 bumping as patch because we bumped to 0.3.0 recently, as part of other (unreleased) go-ipfs 0.13 work This commit was moved from ipfs/go-ipfs-http-client@ecf364c989
This commit is contained in:
parent
ebb2807dcc
commit
fd209019f2
@ -7,9 +7,10 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
iface "github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
mc "github.com/multiformats/go-multicodec"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
)
|
||||
|
||||
@ -31,20 +32,33 @@ func (s *blockStat) Path() path.Resolved {
|
||||
}
|
||||
|
||||
func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error) {
|
||||
options, _, err := caopts.BlockPutOptions(opts...)
|
||||
options, err := caopts.BlockPutOptions(opts...)
|
||||
px := options.CidPrefix
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mht, ok := mh.Codes[options.MhType]
|
||||
mht, ok := mh.Codes[px.MhType]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
|
||||
return nil, fmt.Errorf("unknowm mhType %d", px.MhType)
|
||||
}
|
||||
|
||||
var cidOptKey, cidOptVal string
|
||||
switch {
|
||||
case px.Version == 0 && px.Codec == cid.DagProtobuf:
|
||||
// ensure legacy --format=v0 passes as BlockPutOption still works
|
||||
cidOptKey = "format"
|
||||
cidOptVal = "v0"
|
||||
default:
|
||||
// pass codec as string
|
||||
cidOptKey = "cid-codec"
|
||||
cidOptVal = mc.Code(px.Codec).String()
|
||||
}
|
||||
|
||||
req := api.core().Request("block/put").
|
||||
Option("mhtype", mht).
|
||||
Option("mhlen", options.MhLength).
|
||||
Option("format", options.Codec).
|
||||
Option("mhlen", px.MhLength).
|
||||
Option(cidOptKey, cidOptVal).
|
||||
Option("pin", options.Pin).
|
||||
FileBody(r)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user