diff --git a/gateway/gateway.go b/gateway/gateway.go index 5ed53d0ad..34fab0f5f 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -6,7 +6,6 @@ import ( "sort" cid "github.com/ipfs/go-cid" - ipld "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-libipfs/blocks" "github.com/ipfs/go-libipfs/files" iface "github.com/ipfs/interface-go-ipfs-core" @@ -33,16 +32,13 @@ type NodeAPI interface { // GetBlock attempts to resolve the path and return a reader for data in the block. GetBlock(context.Context, cid.Cid) (blocks.Block, error) - // IsCached returns whether or not the path exists locally. - IsCached(context.Context, path.Path) bool - - // GetIPLDNode returns the IPLD node for the path. - GetIPLDNode(context.Context, cid.Cid) (ipld.Node, error) - // GetIPNSRecord retrieves the best IPNS record for a given CID (libp2p-key) // from the routing system. GetIPNSRecord(context.Context, cid.Cid) ([]byte, error) + // IsCached returns whether or not the path exists locally. + IsCached(context.Context, path.Path) bool + // ResolvePath resolves the path using UnixFS resolver ResolvePath(context.Context, path.Path) (path.Resolved, error) } diff --git a/gateway/handler_codec.go b/gateway/handler_codec.go index f7723d963..ba981cd02 100644 --- a/gateway/handler_codec.go +++ b/gateway/handler_codec.go @@ -10,11 +10,10 @@ import ( "time" cid "github.com/ipfs/go-cid" - ipldlegacy "github.com/ipfs/go-ipld-legacy" "github.com/ipfs/go-libipfs/gateway/assets" ipath "github.com/ipfs/interface-go-ipfs-core/path" - "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/multicodec" + "github.com/ipld/go-ipld-prime/node/basicnode" mc "github.com/multiformats/go-multicodec" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -176,19 +175,26 @@ func (i *handler) serveCodecRaw(ctx context.Context, w http.ResponseWriter, r *h // serveCodecConverted returns payload converted to codec specified in toCodec func (i *handler) serveCodecConverted(ctx context.Context, w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentPath ipath.Path, toCodec mc.Code, modtime time.Time) { - obj, err := i.api.GetIPLDNode(ctx, resolvedPath.Cid()) + blockCid := resolvedPath.Cid() + block, err := i.api.GetBlock(ctx, blockCid) if err != nil { - webError(w, "ipfs dag get "+html.EscapeString(resolvedPath.String()), err, http.StatusInternalServerError) + webError(w, "ipfs block get "+html.EscapeString(resolvedPath.String()), err, http.StatusInternalServerError) return } - universal, ok := obj.(ipldlegacy.UniversalNode) - if !ok { - err = fmt.Errorf("%T is not a valid IPLD node", obj) + codec := blockCid.Prefix().Codec + decoder, err := multicodec.LookupDecoder(codec) + if err != nil { + webError(w, err.Error(), err, http.StatusInternalServerError) + return + } + + node := basicnode.Prototype.Any.NewBuilder() + err = decoder(node, bytes.NewReader(block.RawData())) + if err != nil { webError(w, err.Error(), err, http.StatusInternalServerError) return } - finalNode := universal.(ipld.Node) encoder, err := multicodec.LookupEncoder(uint64(toCodec)) if err != nil { @@ -198,7 +204,7 @@ func (i *handler) serveCodecConverted(ctx context.Context, w http.ResponseWriter // Ensure IPLD node conforms to the codec specification. var buf bytes.Buffer - err = encoder(finalNode, &buf) + err = encoder(node.Build(), &buf) if err != nil { webError(w, err.Error(), err, http.StatusInternalServerError) return diff --git a/go.mod b/go.mod index 859002852..cd213febb 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( github.com/ipfs/go-ipfs-routing v0.3.0 github.com/ipfs/go-ipfs-util v0.0.2 github.com/ipfs/go-ipld-format v0.4.0 - github.com/ipfs/go-ipld-legacy v0.1.1 github.com/ipfs/go-ipns v0.3.0 github.com/ipfs/go-log v1.0.5 github.com/ipfs/go-log/v2 v2.5.1 @@ -73,6 +72,7 @@ require ( github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect github.com/ipfs/go-ipfs-pq v0.0.2 // indirect github.com/ipfs/go-ipld-cbor v0.0.6 // indirect + github.com/ipfs/go-ipld-legacy v0.1.1 // indirect github.com/ipfs/go-merkledag v0.9.0 // indirect github.com/ipfs/go-verifcid v0.0.2 // indirect github.com/ipld/go-codec-dagpb v1.5.0 // indirect