Skip to content

Commit

Permalink
fix chain suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed Nov 21, 2023
1 parent 3e91456 commit 0f47aff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 20 additions & 0 deletions pkg/snapshot/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package snapshot

import (
"encoding/json"
"strings"
)

type SnapshotHeader struct {
Expand All @@ -26,3 +27,22 @@ 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]
}

chainName = strings.ToLower(chainName)

if chainName == "ithacanet" {
chainName = "ghostnet"
}

return chainName
}
9 changes: 1 addition & 8 deletions pkg/store/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.")

Expand Down

0 comments on commit 0f47aff

Please sign in to comment.