Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Nov 18, 2023
1 parent 15c5aed commit f9db96a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
}

#canvas {
width: 854px;
height: 480px;
width: {{.Width}}px;
height: {{.Height}}px;
}
</style>
</head>
Expand Down
58 changes: 52 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net/http"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -127,10 +128,24 @@ type Params struct {
Organization string `param:"org"`
Repository string `param:"repo"`
Release string `param:"release"`
Format string `param:"format"`
}

func (p *Params) Sha1() string {
triplet := fmt.Sprintf("v1%s%s%s%s", p.Runtime, p.Organization, p.Repository, p.Release)
var sb strings.Builder
sb.WriteString("/")
sb.WriteString(p.Runtime)
sb.WriteString("/")
sb.WriteString(p.Organization)
sb.WriteString("/")
sb.WriteString(p.Repository)
sb.WriteString("/")
sb.WriteString(p.Release)
sb.WriteString("/")
sb.WriteString(p.Format)
sb.WriteString("/")

triplet := sb.String()

hash := sha1.New()
//nolint:errcheck
Expand All @@ -144,10 +159,41 @@ func indexHandler(c echo.Context) error {
return fmt.Errorf("parse parameters error: %w", err)
}

var sb strings.Builder
sb.WriteString("/")
sb.WriteString(p.Runtime)
sb.WriteString("/")
sb.WriteString(p.Organization)
sb.WriteString("/")
sb.WriteString(p.Repository)
sb.WriteString("/")
sb.WriteString(p.Release)
sb.WriteString("/")
sb.WriteString(p.Format)
sb.WriteString("/")

var formats = map[string]struct {
width int
height int
}{
"480p": {854, 480},
"720p": {1280, 720},
"1080p": {1920, 1080},
}

format, ok := formats[p.Format]
if !ok {
return fmt.Errorf("invalid format: %s", p.Format)
}

data := struct {
BaseURL string
Width int
Height int
}{
BaseURL: fmt.Sprintf("/%s/%s/%s/%s/", p.Runtime, p.Organization, p.Repository, p.Release),
BaseURL: sb.String(),
Width: format.width,
Height: format.height,
}

tmpl, err := template.New("index").Parse(string(html))
Expand Down Expand Up @@ -229,10 +275,10 @@ func main() {
e.Pre(middleware.RemoveTrailingSlash())
e.Pre(middleware.GzipWithConfig(middleware.GzipConfig{MinLength: 2048}))

e.GET("/:runtime/:org/:repo/:release", indexHandler)
e.GET("/:runtime/:org/:repo/:release/carimbo.js", javaScriptHandler)
e.GET("/:runtime/:org/:repo/:release/carimbo.wasm", webAssemblyHandler)
e.GET("/:runtime/:org/:repo/:release/bundle.7z", bundleHandler)
e.GET("/:runtime/:org/:repo/:release/:format", indexHandler)
e.GET("/:runtime/:org/:repo/:release/:format/carimbo.js", javaScriptHandler)
e.GET("/:runtime/:org/:repo/:release/:format/carimbo.wasm", webAssemblyHandler)
e.GET("/:runtime/:org/:repo/:release/:format/bundle.7z", bundleHandler)
e.GET("/favicon.ico", favIconHandler)

e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", os.Getenv("PORT"))))
Expand Down

0 comments on commit f9db96a

Please sign in to comment.