Ver Fonte

Fix frontend fs util.

ZRY há 8 meses atrás
pai
commit
b018a38745
2 ficheiros alterados com 26 adições e 2 exclusões
  1. 23 2
      websubsvc/frontend_fs.go
  2. 3 0
      websubsvc/frontend_util.go

+ 23 - 2
websubsvc/frontend_fs.go

@@ -3,9 +3,30 @@ package websubsvc
 import (
 	"io/fs"
 	"os"
+	"path"
 )
 
 type IFilesystem interface {
-	fs.FS
-	Stat(path string) (os.FileInfo, error)
+	fs.StatFS
+}
+
+var _ IFilesystem = (*OsFsWithPrefix)(nil)
+
+type OsFsWithPrefix struct {
+	prefix string
+}
+
+func NewOsFsWithPrefix(prefix string) *OsFsWithPrefix {
+	f := &OsFsWithPrefix{
+		prefix: prefix,
+	}
+	return f
+}
+
+func (o OsFsWithPrefix) Open(name string) (fs.File, error) {
+	return os.Open(path.Join(o.prefix, name))
+}
+
+func (o OsFsWithPrefix) Stat(name string) (fs.FileInfo, error) {
+	return os.Stat(path.Join(o.prefix, name))
 }

+ 3 - 0
websubsvc/frontend_util.go

@@ -1,6 +1,7 @@
 package websubsvc
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"net/http"
 	"path"
@@ -29,6 +30,7 @@ func (s *FrontendUtil) StaticFilesHandler(ctx *gin.Context) {
 	url := ctx.Request.URL.Path
 	fin, err := s.filesystem.Stat(path.Clean(url))
 	if err != nil {
+		fmt.Println("[TEST] err in STAT file: ", err)
 		if s.vueHistoryMode {
 			s.VueHistoryModeHandler(ctx)
 			return
@@ -40,6 +42,7 @@ func (s *FrontendUtil) StaticFilesHandler(ctx *gin.Context) {
 	if fin.IsDir() {
 		_, xerr := s.filesystem.Stat(path.Join(path.Clean(url), "index.html"))
 		if xerr != nil {
+			fmt.Println("[TEST] err in STAT index.html: ", xerr)
 			if s.vueHistoryMode {
 				s.VueHistoryModeHandler(ctx)
 				return