Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estuary gw retrieval #548

Merged
merged 7 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions cmd/estuary-shuttle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,10 +1336,11 @@ func (s *Shuttle) handleAdd(c echo.Context, u *User) error {
}

return c.JSON(http.StatusOK, &util.ContentAddResponse{
Cid: nd.Cid().String(),
RetrievalURL: util.CreateRetrievalURL(nd.Cid().String()),
EstuaryId: contid,
Providers: s.addrsForShuttle(),
Cid: nd.Cid().String(),
RetrievalURL: util.CreateDwebRetrievalURL(nd.Cid().String()),
EstuaryRetrievalURL: util.CreateEstuaryRetrievalURL(nd.Cid().String()),
anjor marked this conversation as resolved.
Show resolved Hide resolved
EstuaryId: contid,
Providers: s.addrsForShuttle(),
})
}

Expand Down Expand Up @@ -1478,10 +1479,11 @@ func (s *Shuttle) handleAddCar(c echo.Context, u *User) error {
}

return c.JSON(http.StatusOK, &util.ContentAddResponse{
Cid: root.String(),
RetrievalURL: util.CreateRetrievalURL(root.String()),
EstuaryId: contid,
Providers: s.addrsForShuttle(),
Cid: root.String(),
RetrievalURL: util.CreateDwebRetrievalURL(root.String()),
EstuaryRetrievalURL: util.CreateEstuaryRetrievalURL(root.String()),
EstuaryId: contid,
Providers: s.addrsForShuttle(),
})
}

Expand Down Expand Up @@ -2411,10 +2413,11 @@ func (s *Shuttle) handleImportDeal(c echo.Context, u *User) error {
s.sendPinCompleteMessage(ctx, contid, totalSize, objects)

return c.JSON(http.StatusOK, &util.ContentAddResponse{
Cid: cc.String(),
RetrievalURL: util.CreateRetrievalURL(cc.String()),
EstuaryId: contid,
Providers: s.addrsForShuttle(),
Cid: cc.String(),
RetrievalURL: util.CreateDwebRetrievalURL(cc.String()),
EstuaryRetrievalURL: util.CreateEstuaryRetrievalURL(cc.String()),
EstuaryId: contid,
Providers: s.addrsForShuttle(),
})
}

Expand Down
3 changes: 3 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3234,6 +3234,9 @@ const docTemplate = `{
"estuaryId": {
"type": "integer"
},
"estuary_retrieval_url": {
"type": "string"
},
"providers": {
"type": "array",
"items": {
Expand Down
3 changes: 3 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,9 @@
"estuaryId": {
"type": "integer"
},
"estuary_retrieval_url": {
"type": "string"
},
"providers": {
"type": "array",
"items": {
Expand Down
2 changes: 2 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ definitions:
properties:
cid:
type: string
estuary_retrieval_url:
type: string
estuaryId:
type: integer
providers:
Expand Down
18 changes: 10 additions & 8 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,11 @@ func (s *Server) handleAddCar(c echo.Context, u *util.User) error {
}()

return c.JSON(http.StatusOK, &util.ContentAddResponse{
Cid: rootCID.String(),
RetrievalURL: util.CreateRetrievalURL(rootCID.String()),
EstuaryId: cont.ID,
Providers: s.CM.PinDelegatesForContent(*cont),
Cid: rootCID.String(),
RetrievalURL: util.CreateDwebRetrievalURL(rootCID.String()),
EstuaryRetrievalURL: util.CreateEstuaryRetrievalURL(rootCID.String()),
EstuaryId: cont.ID,
Providers: s.CM.PinDelegatesForContent(*cont),
})
}

Expand Down Expand Up @@ -999,10 +1000,11 @@ func (s *Server) handleAdd(c echo.Context, u *util.User) error {
}()

return c.JSON(http.StatusOK, &util.ContentAddResponse{
Cid: nd.Cid().String(),
RetrievalURL: util.CreateRetrievalURL(nd.Cid().String()),
EstuaryId: content.ID,
Providers: s.CM.PinDelegatesForContent(*content),
Cid: nd.Cid().String(),
RetrievalURL: util.CreateDwebRetrievalURL(nd.Cid().String()),
EstuaryRetrievalURL: util.CreateEstuaryRetrievalURL(nd.Cid().String()),
EstuaryId: content.ID,
Providers: s.CM.PinDelegatesForContent(*content),
})
}

Expand Down
15 changes: 10 additions & 5 deletions util/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ type ContentAddIpfsBody struct {
}

type ContentAddResponse struct {
Cid string `json:"cid"`
RetrievalURL string `json:"retrieval_url"`
EstuaryId uint `json:"estuaryId"`
Providers []string `json:"providers"`
Cid string `json:"cid"`
RetrievalURL string `json:"retrieval_url"`
EstuaryRetrievalURL string `json:"estuary_retrieval_url"`
EstuaryId uint `json:"estuaryId"`
Providers []string `json:"providers"`
}

type ContentCreateBody struct {
Expand Down Expand Up @@ -188,10 +189,14 @@ func EnsurePathIsLinked(dirs []string, rootNode *merkledag.ProtoNode, ds format.
return lookupNode, nil
}

func CreateRetrievalURL(cid string) string {
func CreateDwebRetrievalURL(cid string) string {
return fmt.Sprintf("https://dweb.link/ipfs/%s", cid)
}

func CreateEstuaryRetrievalURL(cid string) string {
return fmt.Sprintf("https://api.estuary.tech/gw/ipfs/%s", cid)
}

func GetContent(contentid string, db *gorm.DB, u *User) (Content, error) {
var content Content
if err := db.First(&content, "id = ?", contentid).Error; err != nil {
Expand Down