diff --git a/Taskfile.yml b/Taskfile.yml index 66658af..f49e14c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,9 +1,9 @@ -version: '3' +version: "3" tasks: install: cmds: - - cmd: go install ./cmd/cli + # Empty for now generate: cmds: diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 528fb11..d247ac4 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -175,7 +175,7 @@ func viewWebsite(scAddress string, config *pkgConfig.Config) error { zipFile, err := websiteManager.RequestWebsite(scAddress, config) if err != nil { - return fmt.Errorf("failed to check website cache: %v", err) + return fmt.Errorf("failed to request website: %v", err) } fileName := "index.html" diff --git a/int/zipper/zipper.go b/int/zipper/zipper.go index 6322618..9642692 100644 --- a/int/zipper/zipper.go +++ b/int/zipper/zipper.go @@ -5,8 +5,6 @@ import ( "bytes" "fmt" "io" - - "github.com/massalabs/station/pkg/logger" ) // ReadIndexFromZip returns the content of the desired file from the given zip file. @@ -15,7 +13,7 @@ func ReadFileFromZip(zipFile []byte, fileName string) ([]byte, error) { zipReader, err := zip.NewReader(reader, int64(reader.Len())) if err != nil { - logger.Errorf("failed to initiate reader: %v", err) + return nil, fmt.Errorf("failed to initiate reader: %v", err) } for _, file := range zipReader.File { diff --git a/pkg/websiteManager/websiteManager.go b/pkg/websiteManager/websiteManager.go index 43a6fed..b4e5bc7 100644 --- a/pkg/websiteManager/websiteManager.go +++ b/pkg/websiteManager/websiteManager.go @@ -24,6 +24,8 @@ func RequestWebsite(scAddress string, config *pkgConfig.Config) ([]byte, error) shouldFetchWebsite := shouldFetch(fileName, cache, lastUpdated, creationDate) if !shouldFetchWebsite { + logger.Debugf("Website %s present in cache and is up to date", scAddress) + content, err := cache.Read(fileName) if err != nil { return nil, fmt.Errorf("failed to read cached website: %w", err) @@ -32,20 +34,20 @@ func RequestWebsite(scAddress string, config *pkgConfig.Config) ([]byte, error) return content, nil } - logger.Infof("Website not found in cache, fetching from network: %s", fileName) + logger.Debugf("Website %s not found in cache or not up to date, fetching...", scAddress) websiteBytes, err := website.Fetch(&config.NetworkInfos, scAddress) if err != nil { return nil, fmt.Errorf("failed to fetch website: %w", err) } - logger.Infof("Website fetched successfully with size: %d bytes", len(websiteBytes)) + logger.Debugf("Website fetched successfully with size: %d bytes", len(websiteBytes)) if err := cache.Save(fileName, websiteBytes); err != nil { return nil, fmt.Errorf("failed to save website to cache: %w", err) } - logger.Infof("Website successfully written to cache at: %s", fileName) + logger.Debugf("Website successfully written to cache at: %s", fileName) return websiteBytes, nil } @@ -56,9 +58,9 @@ func shouldFetch(fileName string, cache *cache.Cache, lastUpdated, creationDate isFileOutdated := lastUpdated.After(creationDate) if isFilePresent { - logger.Infof("Website found in cache: %s", fileName) + logger.Debugf("Website found in cache: %s", fileName) } else { - logger.Infof("Website not found in cache: %s", fileName) + logger.Debugf("Website not found in cache: %s", fileName) } if isFileOutdated { @@ -67,5 +69,5 @@ func shouldFetch(fileName string, cache *cache.Cache, lastUpdated, creationDate logger.Infof("Website is up to date, no need to fetch: %s", fileName) } - return isFileOutdated && !isFilePresent + return isFileOutdated || !isFilePresent }