From db8ed2e83030303cf41664dab108af1d107538a2 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 20 Oct 2026 23:27:28 +0000 Subject: [PATCH] move all static assets under /websrc/* endpoint --- app/app.go | 32 +++------- web/embed.go | 8 +-- web/html/account.html | 12 ++-- web/html/backups.html | 6 +- web/html/config.html | 10 ++-- web/html/index.html | 14 ++--- web/html/login.html | 6 +- web/html/settings.html | 4 +- web/scripts/dialog.js | 6 +- web/scripts/draggable.js | 2 +- web/scripts/index.js | 2 +- web/templates/backups.go.tmpl | 36 +++++------ web/templates/base.go.tmpl | 10 ++-- web/templates/config.go.tmpl | 90 ++++++++++++++-------------- web/templates/instance-card.go.tmpl | 60 +++++++++---------- web/templates/resource-chart.go.tmpl | 4 +- 16 files changed, 139 insertions(+), 163 deletions(-) diff --git a/app/app.go b/app/app.go index 62a5897..c4fc411 100644 --- a/app/app.go +++ b/app/app.go @@ -6,6 +6,7 @@ import ( "log" "proxmoxaas-dashboard/app/common" "proxmoxaas-dashboard/app/routes" + "strings" "web" // go will complain here until the first build "github.com/gin-gonic/gin" @@ -49,31 +50,12 @@ func Run() { // setup static resources under web (css, images, modules, scripts) func ServeStatic(router *gin.Engine, m *minify.M) { - css := common.MinifyStatic(m, web.CSS_fs) - router.GET("/css/*css", func(c *gin.Context) { - path, _ := c.Params.Get("css") - data := css[fmt.Sprintf("css%s", path)] - c.Header("Content-Encoding", data.MimeType.Encoding) - c.Data(200, data.MimeType.Type, []byte(data.Data)) - }) - images := common.MinifyStatic(m, web.Images_fs) - router.GET("/images/*image", func(c *gin.Context) { - path, _ := c.Params.Get("image") - data := images[fmt.Sprintf("images%s", path)] - c.Header("Content-Encoding", data.MimeType.Encoding) - c.Data(200, data.MimeType.Type, []byte(data.Data)) - }) - modules := common.MinifyStatic(m, web.Modules_fs) - router.GET("/modules/*module", func(c *gin.Context) { - path, _ := c.Params.Get("module") - data := modules[fmt.Sprintf("modules%s", path)] - c.Header("Content-Encoding", data.MimeType.Encoding) - c.Data(200, data.MimeType.Type, []byte(data.Data)) - }) - scripts := common.MinifyStatic(m, web.Scripts_fs) - router.GET("/scripts/*script", func(c *gin.Context) { - path, _ := c.Params.Get("script") - data := scripts[fmt.Sprintf("scripts%s", path)] + static := common.MinifyStatic(m, web.Static) + router.GET("/websrc/*path", func(c *gin.Context) { + path, _ := c.Params.Get("path") + trimed_path := strings.Replace(path, "/", "", 1) // replace leading "/" captured by *path + data := static[trimed_path] + fmt.Println(path) c.Header("Content-Encoding", data.MimeType.Encoding) c.Data(200, data.MimeType.Type, []byte(data.Data)) }) diff --git a/web/embed.go b/web/embed.go index dad452b..99be8f9 100644 --- a/web/embed.go +++ b/web/embed.go @@ -5,16 +5,10 @@ import ( ) //go:embed css/* -var CSS_fs embed.FS - //go:embed images/* -var Images_fs embed.FS - //go:embed modules/* -var Modules_fs embed.FS - //go:embed scripts/* -var Scripts_fs embed.FS +var Static embed.FS //go:embed html/* //go:embed templates/* diff --git a/web/html/account.html b/web/html/account.html index d2b2352..30e1139 100644 --- a/web/html/account.html +++ b/web/html/account.html @@ -2,9 +2,9 @@ {{template "head" .}} - - - + + + diff --git a/web/html/config.html b/web/html/config.html index 557fc67..d33caa3 100644 --- a/web/html/config.html +++ b/web/html/config.html @@ -2,11 +2,11 @@ {{template "head" .}} - - - - - + + + + +