Compare commits

..

No commits in common. "551fcee088138b26dba09f11c75ec01682cab5fd" and "a7b5f6de1427cc1960592fe9bdcf40907fd4934b" have entirely different histories.

7 changed files with 56 additions and 141 deletions

View file

@ -1,48 +0,0 @@
body {
font-family: sans-serif;
max-width: 45rem;
margin: 0 auto;
padding: 1rem;
}
img,
video {
max-width: 100%;
}
abbr {
color: gray;
}
pre {
overflow-x: auto;
}
blockquote {
border-left: solid 3px;
margin: auto .5em;
padding-left: 1em;
}
.dinero {
color: green;
}
@media (prefers-color-scheme: dark) {
body {
background: black;
color: #eee;
}
abbr {
color: lightgray;
}
a {
color: gold;
}
a:visited {
color: #ff9;
}
.dinero {
color: lightgreen;
}
}

View file

@ -1,19 +1,22 @@
<!doctype html> <!doctype html>
<meta charset=utf8> <meta charset=utf8>
<meta name=viewport content='width=device-width, initial-scale=1.0'> <meta name=viewport content='width=device-width, initial-scale=1.0'>
<link rel=stylesheet href=/static/assets/drip.css> <link rel=stylesheet href=https://nulo.in/drip.css>
<title>NFTmashin</title>
{{template "meta" .}} <section style=text-align:center>
<h1>NFTmashin</h1>
{{template "body" .}} <p><em>Beta: las copias pueden ser eliminadas en el futuro.</em></p>
<p>NFTs descargados: {{ .NFTNum }}</p>
<footer> <p>Valor total: <span style=color:green>USD ${{ printf "%.2f" .TotalUSDValue }}</span></p>
<a style=font-size:3rem href=/copiar>¡Copiar un NFT!</a>
<p>Inspirado en <a href="https://konsthack.se/portfolio/kh000-kopimashin/" rel="noreferrer noopener">Kopimashin</a> de brokep.</p> <p>Inspirado en <a href="https://konsthack.se/portfolio/kh000-kopimashin/" rel="noreferrer noopener">Kopimashin</a> de brokep.</p>
<p><a href="https://es.wikipedia.org/wiki/Kopimismo" rel="noreferrer noopener"><img style="width: 5rem;box-shadow: 0 0 10px #555;border-radius: 10px;background: #555;padding: .5em;" src="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8' standalone='no'%3F%3E%3Csvg xmlns='http://www.w3.org/2000/svg' height='602.67' width='579.07' stroke='%23ffffff' stroke-width='1.3028' viewBox='0 0 612 792'%3E%3Cpath d='m441.08 720.52l-93.24 66.61-417.03-295.1 0.004-251.03 93.239-65.58 149.6 104.51v-210.05l93.24-66.6 94.27 66.604v210.05l67.62-47.13 79.93 56.36 80.94-57.39 94.26 66.61v251.03l-94.26 65.58-80.94-57.38-67.63 48.15z'/%3E%3Cpath d='m-43.573 241l67.626 48.16 68.65-48.16-68.65-48.16zm80.948 57.38l67.625 48.15 68.65-48.15-67.62-48.17zm79.925 57.37l68.64 48.16 68.66-48.16-68.66-48.15zm149.59-334.03l-68.65 48.16 68.65 48.156 68.65-48.156zm0 114.76l-68.65 48.16 68.65 48.16 67.63-49.18zm0 113.74l-68.65 48.16 68.65 48.15 67.63-48.15zm-68.65 162.91l68.65 47.14 67.63-48.16-67.63-47.14zm80.95 56.35l68.65 48.16 67.62-48.16-67.62-48.15zm149.59-219.26l-68.65 48.16 67.63 48.15 68.65-48.15zm160.87 0l-67.63 48.16 67.63 48.15 68.65-48.15z' fill='%23fff'/%3E%3C/svg%3E" alt="Kopimi"></a></p> <p><a href="https://es.wikipedia.org/wiki/Kopimismo" rel="noreferrer noopener"><img style="width: 5rem;box-shadow: 0 0 10px #555;border-radius: 10px;background: #555;padding: .5em;" src="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8' standalone='no'%3F%3E%3Csvg xmlns='http://www.w3.org/2000/svg' height='602.67' width='579.07' stroke='%23ffffff' stroke-width='1.3028' viewBox='0 0 612 792'%3E%3Cpath d='m441.08 720.52l-93.24 66.61-417.03-295.1 0.004-251.03 93.239-65.58 149.6 104.51v-210.05l93.24-66.6 94.27 66.604v210.05l67.62-47.13 79.93 56.36 80.94-57.39 94.26 66.61v251.03l-94.26 65.58-80.94-57.38-67.63 48.15z'/%3E%3Cpath d='m-43.573 241l67.626 48.16 68.65-48.16-68.65-48.16zm80.948 57.38l67.625 48.15 68.65-48.15-67.62-48.17zm79.925 57.37l68.64 48.16 68.66-48.16-68.66-48.15zm149.59-334.03l-68.65 48.16 68.65 48.156 68.65-48.156zm0 114.76l-68.65 48.16 68.65 48.16 67.63-49.18zm0 113.74l-68.65 48.16 68.65 48.15 67.63-48.15zm-68.65 162.91l68.65 47.14 67.63-48.16-67.63-47.14zm80.95 56.35l68.65 48.16 67.62-48.16-67.62-48.15zm149.59-219.26l-68.65 48.16 67.63 48.15 68.65-48.15zm160.87 0l-67.63 48.16 67.63 48.15 68.65-48.15z' fill='%23fff'/%3E%3C/svg%3E" alt="Kopimi"></a></p>
</footer> </section>
<section>
{{define "meta"}} <h2>Algunos NFTs descargados</h2>
<title>NFTmashin</title> {{range .NFTs}}
{{end}} <a href="/nfts/{{.}}">
{{define "body"}} <img src="/static/nfts/{{.}}">
</a>
{{end}} {{end}}
</section>

62
main.go
View file

@ -9,7 +9,6 @@ import (
"log" "log"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -20,7 +19,7 @@ import (
type Status struct { type Status struct {
NFTNum int NFTNum int
TotalUSDValue float64 TotalUSDValue float64
NFTs []downloadedOpenSeaAsset NFTs []string
} }
const NFTS_DIR = "./nfts" const NFTS_DIR = "./nfts"
@ -65,7 +64,7 @@ func getStatus() (Status, error) {
} }
if len(status.NFTs) <= 20 { if len(status.NFTs) <= 20 {
status.NFTs = append(status.NFTs, asset) status.NFTs = append(status.NFTs, id)
} }
status.NFTNum += 1 status.NFTNum += 1
@ -100,56 +99,41 @@ func getRandomOpenSeaAsset() (Asset, error) {
} }
type downloadedOpenSeaAsset struct { type downloadedOpenSeaAsset struct {
Id string `json:"Id"`
Asset `json:"Asset"` Asset `json:"Asset"`
Transaction `json:"Transaction"` Transaction `json:"Transaction"`
FileName string `json:"FileName"`
} }
func (d downloadedOpenSeaAsset) GetUSDPrice() float64 { func (d downloadedOpenSeaAsset) GetUSDPrice() float64 {
return d.Transaction.Value * d.Asset.LastSale.TokenUSDPrice return d.Transaction.Value * d.Asset.LastSale.TokenUSDPrice
} }
func (d downloadedOpenSeaAsset) IsVideo() bool {
return path.Ext(d.FileName) == ".mp4"
}
func downloadOpenSeaAsset(asset Asset, transaction Transaction) (string, error) { func downloadOpenSeaAsset(asset Asset, transaction Transaction) (string, error) {
id := getOpenSeaId(asset.TokenId) id := getOpenSeaId(asset.TokenId)
u, err := url.Parse(asset.ImageUrl)
if err != nil {
return "", err
}
ext := path.Ext(u.Path)
filename := id + ext
imageRes, err := http.DefaultClient.Get(asset.ImageUrl)
if err != nil {
return "", err
}
file, err := os.Create(filepath.Join(NFTS_DIR, filename))
if err != nil {
return "", err
}
_, err = io.Copy(file, imageRes.Body)
if err != nil {
return "", err
}
jsonFile, err := os.Create(filepath.Join(NFTS_DIR, id+".json")) jsonFile, err := os.Create(filepath.Join(NFTS_DIR, id+".json"))
if err != nil { if err != nil {
return "", err return "", err
} }
err = json.NewEncoder(jsonFile).Encode(downloadedOpenSeaAsset{ err = json.NewEncoder(jsonFile).Encode(downloadedOpenSeaAsset{
Id: id,
Asset: asset, Asset: asset,
Transaction: transaction, Transaction: transaction,
FileName: filename,
}) })
if err != nil { if err != nil {
return "", err return "", err
} }
imageRes, err := http.DefaultClient.Get(asset.ImageUrl)
if err != nil {
return "", err
}
file, err := os.Create(filepath.Join(NFTS_DIR, id))
if err != nil {
return "", err
}
_, err = io.Copy(file, imageRes.Body)
if err != nil {
return "", err
}
return id, nil return id, nil
} }
@ -160,13 +144,13 @@ func must(err error) {
} }
func main() { func main() {
indexTmpl, err := template.ParseFiles("./templates/base.tmpl", "./templates/embed-nft.tmpl", "./templates/index.tmpl") indexTmpl, err := template.ParseFiles("./index.tmpl")
must(err) must(err)
nftsTmpl, err := template.ParseFiles("./templates/base.tmpl", "./templates/embed-nft.tmpl", "./templates/nft.tmpl") nftsTmpl, err := template.ParseFiles("./nft.tmpl")
must(err) must(err)
http.Handle("/static/nfts/", http.StripPrefix("/static/nfts/", http.FileServer(http.Dir(NFTS_DIR)))) fs := http.FileServer(http.Dir(NFTS_DIR))
http.Handle("/static/assets/", http.StripPrefix("/static/assets/", http.FileServer(http.Dir("./assets")))) http.Handle("/static/nfts/", http.StripPrefix("/static/nfts/", fs))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
status, err := getStatus() status, err := getStatus()
@ -216,7 +200,13 @@ func main() {
log.Panicln("No pude conseguir NFT", err) log.Panicln("No pude conseguir NFT", err)
} }
w.Header().Add("Content-Type", "text/html") w.Header().Add("Content-Type", "text/html")
err = nftsTmpl.Execute(w, nft) err = nftsTmpl.Execute(w, struct {
Id string
NFT downloadedOpenSeaAsset
}{
Id: id,
NFT: nft,
})
if err != nil { if err != nil {
log.Panicln("No pude escribir nft", err) log.Panicln("No pude escribir nft", err)
} }

13
nft.tmpl Normal file
View file

@ -0,0 +1,13 @@
<!doctype html>
<meta charset=utf8>
<meta name=viewport content='width=device-width, initial-scale=1.0'>
<link rel=stylesheet href=https://nulo.in/drip.css>
<title>{{ .NFT.Asset.Name }}</title>
<h1>{{ .NFT.Asset.Name }}</h1>
<p>Vendido por <span style=color:green>USD ${{ printf "%.2f" .NFT.GetUSDPrice }}</span></p>
<a href="{{ .NFT.Asset.Permalink }}" rel="noreferrer noopener">Abrir en OpenSea</a>
<figure>
<img src="/static/nfts/{{ .Id }}">
</figure>
<a href=/>Volver</a>

View file

@ -1,7 +0,0 @@
{{define "embed-nft"}}
{{if .IsVideo}}
<video controls loop src="/static/nfts/{{.FileName}}"></video>
{{else}}
<img src="/static/nfts/{{.FileName}}">
{{end}}
{{end}}

View file

@ -1,19 +0,0 @@
{{define "body"}}
<section style=text-align:center>
<h1>NFTmashin</h1>
<p><em>Beta: las copias pueden ser eliminadas en el futuro.</em></p>
<p>NFTs descargados: {{ .NFTNum }}</p>
<p>Valor total: <span class=dinero>USD ${{ printf "%.2f" .TotalUSDValue }}</span></p>
<a style=font-size:3rem href=/copiar>¡Copiar un NFT!</a>
</section>
<section>
<h2>Algunos NFTs descargados</h2>
{{range .NFTs}}
<figure>
<h3><a href="/nfts/{{.Id}}">{{.Asset.Name}}</a></h3>
{{template "embed-nft" .}}
</figure>
<hr>
{{end}}
</section>
{{end}}

View file

@ -1,17 +0,0 @@
{{define "meta"}}
<title>{{ .Asset.Name }}</title>
{{end}}
{{define "body"}}
<h1>{{ .Asset.Name }}</h1>
<p>Vendido por <span style=color:green>USD ${{ printf "%.2f" .GetUSDPrice }}</span></p>
<a href="{{ .Asset.Permalink }}" rel="noreferrer noopener">Abrir en OpenSea</a>
<figure>
{{if .IsVideo}}
<video controls loop src="/static/nfts/{{.FileName}}"></video>
{{else}}
<img src="/static/nfts/{{.FileName}}">
{{end}}
</figure>
<a href=/>Volver</a>
{{end}}