aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--cmd/server/main.go4
-rw-r--r--pkg/ext/fileserver.go18
-rw-r--r--pkg/worker/list_processor_test.go3
-rw-r--r--static.go (renamed from tmpl.go)11
5 files changed, 31 insertions, 7 deletions
diff --git a/README.md b/README.md
index 0940ae4..6103dbf 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ A read only file explorer with media capabilities.
* Thumbnail system
* Initial setup process
* Also allow setup user config file
-* Single binary output
+* ~~Single binary output~~
* Better worker pool. Allow cron job and ui config
* Alpine package and demo site
* Single image viewer and show exif info (not sure how yet)
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 0fa5fea..4ca39de 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -16,6 +16,7 @@ import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
+ "git.sr.ht/~gabrielgio/img"
"git.sr.ht/~gabrielgio/img/pkg/components/auth"
"git.sr.ht/~gabrielgio/img/pkg/components/filesystem"
"git.sr.ht/~gabrielgio/img/pkg/components/media"
@@ -69,8 +70,7 @@ func main() {
}
r := router.New()
- r.ServeFiles("/static/{filepath:*}", "./static")
- r.NotFound = ext.NotFoundHTML
+ r.GET("/static/{filepath:*}", ext.FileServer(img.StaticFS, "static/"))
authMiddleware := ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth"))
logMiddleware := ext.NewLogMiddleare(logger.WithField("context", "http"))
diff --git a/pkg/ext/fileserver.go b/pkg/ext/fileserver.go
new file mode 100644
index 0000000..fdea08e
--- /dev/null
+++ b/pkg/ext/fileserver.go
@@ -0,0 +1,18 @@
+package ext
+
+import (
+ "io/fs"
+
+ "github.com/valyala/fasthttp"
+)
+
+type FileSystem interface {
+ Open(name string) (fs.File, error)
+}
+
+func FileServer(rootFS FileSystem, rootPath string) fasthttp.RequestHandler {
+ return func(r *fasthttp.RequestCtx) {
+ path := r.UserValue("filepath").(string)
+ r.SendFile(rootPath + path)
+ }
+}
diff --git a/pkg/worker/list_processor_test.go b/pkg/worker/list_processor_test.go
index 35672f3..ce3ff0a 100644
--- a/pkg/worker/list_processor_test.go
+++ b/pkg/worker/list_processor_test.go
@@ -9,8 +9,9 @@ import (
"sync"
"testing"
- "git.sr.ht/~gabrielgio/img/pkg/testkit"
"github.com/sirupsen/logrus"
+
+ "git.sr.ht/~gabrielgio/img/pkg/testkit"
)
type (
diff --git a/tmpl.go b/static.go
index b11f962..1c6a086 100644
--- a/tmpl.go
+++ b/static.go
@@ -7,10 +7,15 @@ import (
"io"
)
-//go:embed templates/*.html
-var TemplateFS embed.FS
+var (
+ //go:embed templates/*.html
+ TemplateFS embed.FS
-var Template *template.Template
+ //go:embed static/*
+ StaticFS embed.FS
+
+ Template *template.Template
+)
type HTMLView[T any] struct {
Title string