From e01c148103529d76a037f895cbf75461104a75d4 Mon Sep 17 00:00:00 2001 From: Felipe Cardozo Date: Tue, 21 Nov 2023 16:46:06 -0300 Subject: [PATCH] fix chain suffix --- pkg/snapshot/header.go | 18 ++++++++++++++++++ pkg/store/storage.go | 9 +-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/snapshot/header.go b/pkg/snapshot/header.go index 88dd938..3d4288b 100644 --- a/pkg/snapshot/header.go +++ b/pkg/snapshot/header.go @@ -2,6 +2,7 @@ package snapshot import ( "encoding/json" + "strings" ) type SnapshotHeader struct { @@ -26,3 +27,20 @@ func SnapshotHeaderFromJson(snapshotHeaderOutput string) (*SnapshotHeader, error return &snapshotHeader.SnapshotHeader, nil } + +func (s *SnapshotHeader) SanitizeChainName() string { + chainName := s.ChaiName + if strings.Contains(chainName, "_") { + chainName = strings.Split(chainName, "_")[1] + } + + if strings.Contains(chainName, "-") { + chainName = strings.Split(chainName, "-")[0] + } + + if chainName == "ithacanet" { + chainName = "ghostnet" + } + + return strings.ToLower(chainName) +} diff --git a/pkg/store/storage.go b/pkg/store/storage.go index a674337..0a0b9b5 100644 --- a/pkg/store/storage.go +++ b/pkg/store/storage.go @@ -140,7 +140,7 @@ func (s *SnapshotStorage) GetSnapshotItems(ctx context.Context) []snapshot.Snaps Filename: filename, Filesize: util.FileSize(size), FilesizeBytes: size, - ChainName: RemoveTezosPrefix(snapshotHeader.ChaiName), + ChainName: snapshotHeader.SanitizeChainName(), Date: date, BlockTimestamp: snapshotHeader.Timestamp, URL: obj.MediaLink, @@ -169,13 +169,6 @@ func (s *SnapshotStorage) GetSnapshotItems(ctx context.Context) []snapshot.Snaps return items } -func RemoveTezosPrefix(filename string) string { - if strings.HasPrefix(filename, "TEZOS_") { - return strings.ToLower(filename[6:]) - } - return filename -} - func (s *SnapshotStorage) DeleteExpiredSnapshots(ctx context.Context, maxDays int, maxMonths int) { log.Println("Deleting expired snapshots in the Google Cloud Storage.")