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 ab5ff22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 14 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,16 @@ func SnapshotHeaderFromJson(snapshotHeaderOutput string) (*SnapshotHeader, error

return &snapshotHeader.SnapshotHeader, nil
}

func (s *SnapshotHeader) SanitizeChainName() string {
result := s.ChaiName
if strings.Contains(result, "_") {
result = strings.Split(result, "_")[1]
}

if strings.Contains(result, "-") {
result = strings.Split(result, "-")[0]
}

return strings.ToLower(result)
}
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 ab5ff22

Please sign in to comment.