Skip to content

Commit

Permalink
fix(kiosk): replace packd with a new static handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tgragnato committed Jan 19, 2024
1 parent ac0fa28 commit ba11e11
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 156 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ go 1.21
require (
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.9.1
github.com/gobuffalo/packd v1.0.2
github.com/gosimple/slug v1.13.1
github.com/sirupsen/logrus v1.9.3
github.com/tdewolff/minify/v2 v2.20.14
github.com/tidwall/gjson v1.17.0
github.com/xujiajun/nutsdb v0.11.1
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -35,7 +33,6 @@ require (
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/tdewolff/parse/v2 v2.7.9 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand Down
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/gobuffalo/packd v1.0.2 h1:Yg523YqnOxGIWCp69W12yYBKsoChwI7mtu6ceM9Bwfw=
github.com/gobuffalo/packd v1.0.2/go.mod h1:sUc61tDqGMXON80zpKGp92lDb86Km28jfvX7IAyxFT8=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
Expand Down Expand Up @@ -101,13 +99,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tdewolff/minify/v2 v2.20.14 h1:sktSuVixRwk0ryQjqvKBu/uYS+MWmkwEFMEWtFZ+TdE=
github.com/tdewolff/minify/v2 v2.20.14/go.mod h1:qnIJbnG2dSzk7LIa/UUwgN2OjS8ir6RRlqc0T/1q2xY=
github.com/tdewolff/parse/v2 v2.7.9 h1:4u8nNXNmEGCRVd/slZmZHFL1mv/EVEpHMhSinxdDCqw=
github.com/tdewolff/parse/v2 v2.7.9/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA=
github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739 h1:IkjBCtQOOjIn03u/dMQK9g+Iw9ewps4mCl1nB8Sscbo=
github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
31 changes: 0 additions & 31 deletions kiosk/index.go

This file was deleted.

100 changes: 0 additions & 100 deletions kiosk/minifier/filesystem.go

This file was deleted.

16 changes: 5 additions & 11 deletions kiosk/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@ package kiosk

import (
"embed"
"net/http"
"regexp"

"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
_min "github.com/immobiliare/peephole/kiosk/minifier"
_mold "github.com/immobiliare/peephole/mold"
_event "github.com/immobiliare/peephole/mold/event"
_util "github.com/immobiliare/peephole/util"
"github.com/sirupsen/logrus"
)

// go:embed assets/templates/**
var templates embed.FS

// go:embed assets/static/**
var static embed.FS
//go:embed assets
var assets embed.FS

type Kiosk struct {
mold *_mold.Mold
router *gin.Engine
eventChan chan *_event.Event
config *Config
minifier *_min.FS
}

func init() {
Expand All @@ -41,7 +35,6 @@ func Init(db *_mold.Mold, eventChan chan *_event.Event, config *Config) *Kiosk {
k.mold = db
k.config = config
k.eventChan = eventChan
k.minifier = _min.Init(http.FS(static))

k.router = gin.Default()
k.router.Use(gzip.Gzip(gzip.DefaultCompression))
Expand All @@ -60,8 +53,9 @@ func Init(db *_mold.Mold, eventChan chan *_event.Event, config *Config) *Kiosk {
if len(config.BasicAuth) > 0 {
group = k.router.Group("/", gin.BasicAuth(gin.Accounts(config.BasicAuth)))
}
group.StaticFS("/assets", k.minifier)
group.GET("/", k.indexHandler)

group.GET("/assets/:filename", k.staticHandler)
group.GET("/", k.staticHandler)
group.GET("/events", k.eventsHandler)
group.GET("/events/:jid", k.eventHandler)

Expand Down
28 changes: 28 additions & 0 deletions kiosk/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kiosk

import (
"net/http"

"github.com/gin-gonic/gin"
)

func (k *Kiosk) staticHandler(c *gin.Context) {
filename := c.Param("filename")
if filename == "" {
filename = "assets/index.html"
} else {
filename = "assets/" + filename
}

blob, err := assets.ReadFile(filename)
if err != nil {
c.Status(http.StatusNotFound)
}

contentType := http.DetectContentType(blob)
if filename == "assets/style.css" {
contentType = "text/css; charset=utf-8"
}

c.Data(http.StatusOK, contentType, blob)
}
3 changes: 1 addition & 2 deletions salt/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package salt
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"

"io"

_util "github.com/immobiliare/peephole/util"
"github.com/sirupsen/logrus"
)
Expand Down

0 comments on commit ba11e11

Please sign in to comment.