11package pkg
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "strings"
6+ )
47
58// typeMap maps artifact types to their corresponding file names.
69var TypeMap = map [string ]string {
7- "genesis" : "block0.bin" ,
8- "vit" : "database.sqlite3" ,
10+ "genesis" : "block0-VERSION .bin" ,
11+ "vit" : "database-VERSION .sqlite3" ,
912}
1013
1114// ArtifactFetcher is used to fetch artifacts from a store.
@@ -18,13 +21,7 @@ type ArtifactFetcher struct {
1821// Fetch fetches the given artifact from the store.
1922// If id is empty, it will use the base artifact filename with no version suffix.
2023func (f * ArtifactFetcher ) Fetch (artifactType string , version string ) ([]byte , error ) {
21- var key string
22- if version == "" {
23- key = fmt .Sprintf ("%s/%s/%s" , f .Environment , f .Fund , TypeMap [artifactType ])
24- } else {
25- key = fmt .Sprintf ("%s/%s/%s-%s" , f .Environment , f .Fund , TypeMap [artifactType ], version )
26- }
27-
24+ key := fmt .Sprintf ("%s/%s/%s" , f .Environment , f .Fund , mkFileName (artifactType , f .Fund , version ))
2825 return f .Store .Fetch (key )
2926}
3027
@@ -36,3 +33,10 @@ func NewArtifactFetcher(environment, fund string, store Store) ArtifactFetcher {
3633 Store : store ,
3734 }
3835}
36+
37+ func mkFileName (artifactType , fund , version string ) string {
38+ if version == "" {
39+ return strings .Replace (TypeMap [artifactType ], "-VERSION" , "" , 1 )
40+ }
41+ return strings .Replace (TypeMap [artifactType ], "VERSION" , fmt .Sprintf ("%s-%s" , fund , version ), 1 )
42+ }
0 commit comments