Skip to content

Commit

Permalink
add content status
Browse files Browse the repository at this point in the history
  • Loading branch information
alvin-reyes committed May 25, 2023
1 parent 0800483 commit d0e2059
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
38 changes: 38 additions & 0 deletions api/open_status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@ import (
)

func ConfigureOpenStatusCheckRouter(e *echo.Group, node *core.LightNode) {

e.GET("/status/content/by-cid/:cid", func(c echo.Context) error {

var content core.Content
node.DB.Raw("select * from contents as c where cid = ?", c.Param("cid")).Scan(&content)
content.RequestingApiKey = ""

var buckets []core.Bucket
node.DB.Model(&core.Bucket{}).Where("uuid = ?", content.BucketUuid).Find(&buckets)

var bundles []core.Bundle
for _, bucket := range buckets {
bucket.RequestingApiKey = ""
node.DB.Model(&core.Bundle{}).Where(" uuid = ?", bucket.BundleUuid).Find(&bundles)
for _, bundle := range bundles {
bundle.RequestingApiKey = ""
}
}

if content.ID == 0 {
return c.JSON(404, map[string]interface{}{
"message": "Content not found. Please check if you have the proper API key or if the content id is valid",
})
}
// associated bundle

// trigger status check
job := jobs.CreateNewDispatcher()
job.AddJob(jobs.NewDealItemChecker(node, content))
job.Start(1)

return c.JSON(200, map[string]interface{}{
"content": content,
"buckets": buckets,
"bundles": bundles,
})
})
e.GET("/status/content/:id", func(c echo.Context) error {

var content core.Content
Expand All @@ -21,6 +58,7 @@ func ConfigureOpenStatusCheckRouter(e *echo.Group, node *core.LightNode) {
"message": "Content not found. Please check if you have the proper API key or if the content id is valid",
})
}
// associated bundle

// trigger status check
job := jobs.CreateNewDispatcher()
Expand Down
18 changes: 8 additions & 10 deletions jobs/bucket_car_bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (b BucketCarBundler) Run() error {
var buckets []core.Bucket
b.LightNode.DB.Model(&core.Bucket{}).Where("status = ?", "filled").Find(&buckets)

if len(buckets) < 1 {
if len(buckets) < 3 {
fmt.Println("Not enough buckets to aggregate")
return nil
}
Expand Down Expand Up @@ -98,21 +98,16 @@ func (b BucketCarBundler) Run() error {
panic(err)
}

cidIPC, errPiece := a.IndexPieceCID()
if errPiece != nil {
fmt.Printf("%+v\n", errPiece)
}
fmt.Println("a.IndexPieceCid()", cidIPC)
//cidIPC, errPiece := a.IndexPieceCID()
//if errPiece != nil {
// fmt.Printf("%+v\n", errPiece)
//}

cidPC, errP := a.PieceCID()
fmt.Println("a.PieceCID()", cidPC)
if errP != nil {
fmt.Printf("%+v\n", errP)
}

// process the deal
fmt.Println("rootReader", rootReader)

// add this to the node
rootBundle, err := b.LightNode.Node.AddPinFile(context.Background(), rootReader, nil)
if err != nil {
Expand Down Expand Up @@ -144,10 +139,13 @@ func (b BucketCarBundler) Run() error {

bucketX.CommPa = aux.CommPa.String()
bucketX.SizePa = int64(aux.SizePa)

if err != nil {
panic(err)
}

b.LightNode.DB.Save(bucketX)

}

job := CreateNewDispatcher()
Expand Down

0 comments on commit d0e2059

Please sign in to comment.