Skip to content

Commit

Permalink
fix: move metadata utils to lassie
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Aug 11, 2023
1 parent 27bae29 commit b40900e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 250 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/dustin/go-humanize v1.0.1
github.com/filecoin-project/lassie v0.12.2-0.20230614045620-19b6e938241c
github.com/filecoin-project/lassie v0.14.4-0.20230811071806-0393d52eb17c
github.com/ipfs/go-block-format v0.1.2
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-graphsync v0.14.7
Expand All @@ -13,7 +13,7 @@ require (
github.com/ipfs/go-unixfsnode v1.7.3
github.com/ipld/go-car/v2 v2.10.1
github.com/ipld/go-codec-dagpb v1.6.0
github.com/ipld/go-ipld-prime v0.21.1-0.20230810111002-bdf990edcdeb
github.com/ipld/go-ipld-prime v0.21.1-0.20230811030745-6e31cea491de
github.com/ipni/go-libipni v0.3.4
github.com/ipni/index-provider v0.13.5
github.com/libp2p/go-libp2p v0.29.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNdofHZoGPjfNaAo5Q=
github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo=
github.com/filecoin-project/lassie v0.12.2-0.20230614045620-19b6e938241c h1:2E1hw30L6zKaHsNnqoqXc48A3EDJ/afnGMPFna8c4h0=
github.com/filecoin-project/lassie v0.12.2-0.20230614045620-19b6e938241c/go.mod h1:kbO6Ljk/2ug6CLJuHsgsd4c6EVrAmnVQKFAktmETSI4=
github.com/filecoin-project/lassie v0.14.4-0.20230811071806-0393d52eb17c h1:wyjf1iVe/rT5gJpT1xpvL6kvxZXqLfOQn8hHrAK9O/Y=
github.com/filecoin-project/lassie v0.14.4-0.20230811071806-0393d52eb17c/go.mod h1:4zIWVE9FSeGbx7xQTd9y+vFVt4UIdBxfVxnj4RCI9gM=
github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
Expand Down Expand Up @@ -327,8 +327,8 @@ github.com/ipld/go-codec-dagpb v1.6.0 h1:9nYazfyu9B1p3NAgfVdpRco3Fs2nFC72DqVsMj6
github.com/ipld/go-codec-dagpb v1.6.0/go.mod h1:ANzFhfP2uMJxRBr8CE+WQWs5UsNa0pYtmKZ+agnUw9s=
github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0 h1:QAI/Ridj0+foHD6epbxmB4ugxz9B4vmNdYSmQLGa05E=
github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0/go.mod h1:odxGcpiQZLzP5+yGu84Ljo8y3EzCvNAQKEodHNsHLXA=
github.com/ipld/go-ipld-prime v0.21.1-0.20230810111002-bdf990edcdeb h1:frdDF5813yKhOaEHAdEhgArLVk+uBQwygVtfg2jAGR4=
github.com/ipld/go-ipld-prime v0.21.1-0.20230810111002-bdf990edcdeb/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ=
github.com/ipld/go-ipld-prime v0.21.1-0.20230811030745-6e31cea491de h1:N6Wfk6dvcBjF4AJJDSmti6CkgHWZPDZ0fuqSQL+kKnU=
github.com/ipld/go-ipld-prime v0.21.1-0.20230811030745-6e31cea491de/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ=
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo=
github.com/ipni/go-libipni v0.3.4 h1:ZYgCE2TOZt/QJJcBZb+R63FaBLlA2suZGP2IH1fKv4A=
github.com/ipni/go-libipni v0.3.4/go.mod h1:6EIUhN83pd1i6q7SCSCIuuUC3XgR7D/gjKkEnVyIQWE=
Expand Down
27 changes: 9 additions & 18 deletions httpipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"sync"
"time"

lassiehttp "github.com/filecoin-project/lassie/pkg/server/http"
lassiehttp "github.com/filecoin-project/lassie/pkg/httputil"
"github.com/filecoin-project/lassie/pkg/httputil/metadata"
"github.com/filecoin-project/lassie/pkg/types"

Check failure on line 14 in httpipfs.go

View workflow job for this annotation

GitHub Actions / All

package "github.com/filecoin-project/lassie/pkg/types" is being imported more than once (ST1019)

Check failure on line 14 in httpipfs.go

View workflow job for this annotation

GitHub Actions / All

package "github.com/filecoin-project/lassie/pkg/types" is being imported more than once (ST1019)
lassietypes "github.com/filecoin-project/lassie/pkg/types"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-unixfsnode"
"github.com/ipld/frisbii/metadata"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/linking"
mh "github.com/multiformats/go-multihash"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
return
}

includeDupes, err := lassiehttp.CheckFormat(req)
includeDupes, includeMeta, err := lassiehttp.CheckFormat(req)
if err != nil {
logError(http.StatusBadRequest, err)
return
Expand All @@ -116,8 +117,6 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
return
}

includeMeta := req.URL.Query().Get("meta") == "eof"

if fileName == "" {
fileName = fmt.Sprintf("%s%s", rootCid.String(), lassiehttp.FilenameExtCar)
}
Expand All @@ -130,7 +129,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%q", fileName))
res.Header().Set("Accept-Ranges", lassiehttp.ResponseAcceptRangesHeader)
res.Header().Set("Cache-Control", lassiehttp.ResponseCacheControlHeader)
res.Header().Set("Content-Type", lassiehttp.ResponseContentTypeHeader)
res.Header().Set("Content-Type", lassiehttp.RequestAcceptHeader) // instead of ResponseContentTypeHeader because we are doing meta=eof as well
res.Header().Set("Etag", etag(rootCid, path.String(), dagScope, includeDupes))
res.Header().Set("X-Content-Type-Options", "nosniff")
res.Header().Set("X-Ipfs-Path", "/"+datamodel.ParsePath(req.URL.Path).String())
Expand Down Expand Up @@ -174,7 +173,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
md.Error = &msg
carErr = err
} else {
md.Properties = &metadata.CarProperties{
md.Properties = &types.CarProperties{
CarBytes: writer.(*checksumWriter).Count(),
DataBytes: dataBytes,
BlockCount: blockCount,
Expand All @@ -183,17 +182,9 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
}
}

enc, err := metadata.CarMetadata{Metadata: &md}.Serialize()
if err != nil {
if carErr != nil {
carErr = err
}
} else {
if _, err := res.Write(enc); err != nil {
if carErr != nil {
carErr = err
}
}
err := metadata.CarMetadata{Metadata: &md}.Serialize(res)
if err != nil && carErr != nil {
carErr = err
}
}

Expand Down
76 changes: 0 additions & 76 deletions metadata/metadata.go

This file was deleted.

31 changes: 0 additions & 31 deletions metadata/metadata.ipldsch

This file was deleted.

119 changes: 0 additions & 119 deletions metadata/metadata_test.go

This file was deleted.

0 comments on commit b40900e

Please sign in to comment.