Skip to content

Commit

Permalink
feat: add get file status rest api for indexer gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliqun committed Nov 21, 2024
1 parent 54ba802 commit 2daf5cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions indexer/gateway/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func getFileInfo(ctx context.Context, root common.Hash, txSeq *uint64) (info *no
return nil, errors.New("no clients available")
}

var finalInfo *node.FileInfo
for _, client := range clients {
if txSeq != nil {
info, err = client.GetFileInfoByTxSeq(ctx, *txSeq)
Expand All @@ -172,12 +173,21 @@ func getFileInfo(ctx context.Context, root common.Hash, txSeq *uint64) (info *no
return nil, err
}

if info != nil {
return info, nil
if info == nil {
return nil, nil
}

if finalInfo == nil {
finalInfo = info
}

finalInfo.Finalized = finalInfo.Finalized && info.Finalized
finalInfo.IsCached = finalInfo.IsCached && info.IsCached
finalInfo.Pruned = finalInfo.Pruned || info.Pruned
finalInfo.UploadedSegNum = min(finalInfo.UploadedSegNum, info.UploadedSegNum)
}

return nil, nil
return finalInfo, nil
}

// downloadAndServeFile downloads the file and serves it as an attachment.
Expand Down
1 change: 1 addition & 0 deletions indexer/gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func newRouter() *gin.Engine {
// handlers
router.GET("/file", downloadFile)
router.GET("/file/:cid/*filePath", downloadFileInFolder)
router.GET("/status/:cid", getFileStatus)

Check failure on line 55 in indexer/gateway/server.go

View workflow job for this annotation

GitHub Actions / test

undefined: getFileStatus

Check failure on line 55 in indexer/gateway/server.go

View workflow job for this annotation

GitHub Actions / unit-test

undefined: getFileStatus
router.POST("/file/segment", uploadSegment)

return router
Expand Down

0 comments on commit 2daf5cf

Please sign in to comment.