From 2daf5cf8f5cfad95a46388fd85f22d5cad7f3913 Mon Sep 17 00:00:00 2001 From: Conflux Date: Thu, 21 Nov 2024 18:48:20 +0800 Subject: [PATCH] feat: add get file status rest api for indexer gateway --- indexer/gateway/download.go | 16 +++++++++++++--- indexer/gateway/server.go | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/indexer/gateway/download.go b/indexer/gateway/download.go index d0c6eda..644e9ce 100644 --- a/indexer/gateway/download.go +++ b/indexer/gateway/download.go @@ -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) @@ -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. diff --git a/indexer/gateway/server.go b/indexer/gateway/server.go index 6308d56..b9ad3e2 100644 --- a/indexer/gateway/server.go +++ b/indexer/gateway/server.go @@ -52,6 +52,7 @@ func newRouter() *gin.Engine { // handlers router.GET("/file", downloadFile) router.GET("/file/:cid/*filePath", downloadFileInFolder) + router.GET("/status/:cid", getFileStatus) router.POST("/file/segment", uploadSegment) return router