Skip to content

Commit

Permalink
handle data ruis
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed Feb 23, 2024
1 parent 6bf4811 commit 5895491
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions analyzer/evmnfts/multiproto/multiproto.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package multiproto

import (
"bytes"
"context"
"encoding/base64"
"fmt"
"io"
"net/url"
"strings"

"github.com/oasisprotocol/nexus/analyzer/evmnfts/httpmisc"
"github.com/oasisprotocol/nexus/analyzer/evmnfts/ipfsclient"
Expand Down Expand Up @@ -39,6 +42,16 @@ func Get(ctx context.Context, ipfsClient ipfsclient.Client, whyDidTheyNameTheirL
return nil, fmt.Errorf("IPFS get: %w", err1)
}
return rc, nil
case "data":
// A few NFTs publish their metadata directly in data URIs that look like
// `data:application/json;base64,eyJuYW1lIjogIkZh....`
// In this case we return the base64 encoded data
enc := strings.TrimPrefix(parsed.Opaque, "application/json;base64,")
raw, err1 := base64.StdEncoding.DecodeString(enc)
if err1 != nil {
return nil, fmt.Errorf("unable to b64 decode data: %w", err1)
}
return io.NopCloser(bytes.NewReader(raw)), nil
default:
return nil, fmt.Errorf("unsupported protocol %s", parsed.Scheme)
}
Expand Down

0 comments on commit 5895491

Please sign in to comment.