Skip to content

Commit

Permalink
fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Jul 31, 2024
1 parent 5311808 commit 0d582e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: '3'
version: "3"

tasks:
install:
cmds:
- cmd: go install ./cmd/cli
# Empty for now

generate:
cmds:
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions int/zipper/zipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions pkg/websiteManager/websiteManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}

0 comments on commit 0d582e5

Please sign in to comment.