Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
supreme2580 committed Nov 5, 2024
1 parent e12a930 commit 2127047
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions backend/routes/indexer/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func processNFTMintedEvent(event IndexerEvent) {
"nfts",
fmt.Sprintf("nfts/%s", roundDir),
fmt.Sprintf("nfts/%s/images", roundDir),
fmt.Sprintf("nfts/%s/metadata", roundDir),
fmt.Sprintf("nfts/%s/metadata", roundDir),
}

for _, dir := range dirs {
Expand Down Expand Up @@ -242,7 +242,7 @@ func processNFTMintedEvent(event IndexerEvent) {
return
}

metadataFilename := fmt.Sprintf("nfts/%s/metadata/nft-%d.json", roundDir, tokenId)
metadataFilename := fmt.Sprintf("nfts/%s/metadata/nft-%d.json", roundDir, tokenId)
err = os.WriteFile(metadataFilename, metadataFile, 0644)
if err != nil {
PrintIndexerError("processNFTMintedEvent", "Error writing NFT metadata file", tokenIdLowHex, positionHex, widthHex, heightHex, nameHex, imageHashHex, blockNumberHex, minter)
Expand Down
140 changes: 70 additions & 70 deletions backend/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,76 +15,76 @@ func InitBaseRoutes() {
w.WriteHeader(http.StatusOK)
})

roundNumber := os.Getenv("ROUND_NUMBER")
if roundNumber == "" {
roundNumber = "3"
}

http.HandleFunc(fmt.Sprintf("/round-%s/images/", roundNumber), func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Received request for: %s\n", r.URL.Path)
routeutils.SetupHeaders(w)
// Get just the filename from the path
filename := strings.TrimPrefix(r.URL.Path, fmt.Sprintf("/round-%s/images/", roundNumber))
fmt.Printf("Filename: %s\n", filename)
// Get working directory
workDir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting working directory: %v\n", err)
http.Error(w, "Server error", http.StatusInternalServerError)
return
}
fmt.Printf("Working directory: %s\n", workDir)
// Construct absolute file path
filepath := fmt.Sprintf("%s/nfts/round-%s/images/%s", workDir, roundNumber, filename)
fmt.Printf("Looking for file at: %s\n", filepath)
// Check if file exists
if _, err := os.Stat(filepath); os.IsNotExist(err) {
fmt.Printf("File not found: %s\n", filepath)
http.Error(w, fmt.Sprintf("Image not found at %s", filepath), http.StatusNotFound)
return
}
// Set content type for images
w.Header().Set("Content-Type", "image/png")
fmt.Printf("Serving file: %s\n", filepath)
// Serve the file
http.ServeFile(w, r, filepath)
})

http.HandleFunc(fmt.Sprintf("/round-%s/metadata/", roundNumber), func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Received request for: %s\n", r.URL.Path)
routeutils.SetupHeaders(w)
filename := strings.TrimPrefix(r.URL.Path, fmt.Sprintf("/round-%s/metadata/", roundNumber))
fmt.Printf("Filename: %s\n", filename)
workDir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting working directory: %v\n", err)
http.Error(w, "Server error", http.StatusInternalServerError)
return
}
fmt.Printf("Working directory: %s\n", workDir)
filepath := fmt.Sprintf("%s/nfts/round-%s/metadata/%s", workDir, roundNumber, filename)
fmt.Printf("Looking for file at: %s\n", filepath)
if _, err := os.Stat(filepath); os.IsNotExist(err) {
fmt.Printf("File not found: %s\n", filepath)
http.Error(w, fmt.Sprintf("Metadata not found at %s", filepath), http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Printf("Serving file: %s\n", filepath)
http.ServeFile(w, r, filepath)
})
roundNumber := os.Getenv("ROUND_NUMBER")
if roundNumber == "" {
roundNumber = "3"
}

http.HandleFunc(fmt.Sprintf("/round-%s/images/", roundNumber), func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Received request for: %s\n", r.URL.Path)
routeutils.SetupHeaders(w)

// Get just the filename from the path
filename := strings.TrimPrefix(r.URL.Path, fmt.Sprintf("/round-%s/images/", roundNumber))
fmt.Printf("Filename: %s\n", filename)

// Get working directory
workDir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting working directory: %v\n", err)
http.Error(w, "Server error", http.StatusInternalServerError)
return
}
fmt.Printf("Working directory: %s\n", workDir)

// Construct absolute file path
filepath := fmt.Sprintf("%s/nfts/round-%s/images/%s", workDir, roundNumber, filename)
fmt.Printf("Looking for file at: %s\n", filepath)

// Check if file exists
if _, err := os.Stat(filepath); os.IsNotExist(err) {
fmt.Printf("File not found: %s\n", filepath)
http.Error(w, fmt.Sprintf("Image not found at %s", filepath), http.StatusNotFound)
return
}

// Set content type for images
w.Header().Set("Content-Type", "image/png")

fmt.Printf("Serving file: %s\n", filepath)
// Serve the file
http.ServeFile(w, r, filepath)
})

http.HandleFunc(fmt.Sprintf("/round-%s/metadata/", roundNumber), func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Received request for: %s\n", r.URL.Path)
routeutils.SetupHeaders(w)

filename := strings.TrimPrefix(r.URL.Path, fmt.Sprintf("/round-%s/metadata/", roundNumber))
fmt.Printf("Filename: %s\n", filename)

workDir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting working directory: %v\n", err)
http.Error(w, "Server error", http.StatusInternalServerError)
return
}
fmt.Printf("Working directory: %s\n", workDir)

filepath := fmt.Sprintf("%s/nfts/round-%s/metadata/%s", workDir, roundNumber, filename)
fmt.Printf("Looking for file at: %s\n", filepath)

if _, err := os.Stat(filepath); os.IsNotExist(err) {
fmt.Printf("File not found: %s\n", filepath)
http.Error(w, fmt.Sprintf("Metadata not found at %s", filepath), http.StatusNotFound)
return
}

w.Header().Set("Content-Type", "application/json")

fmt.Printf("Serving file: %s\n", filepath)
http.ServeFile(w, r, filepath)
})
}

func InitRoutes() {
Expand Down

0 comments on commit 2127047

Please sign in to comment.