fix: URL解码处理和移除BOM字符
- 添加assets文件路径的URL解码处理,支持特殊字符 - 添加NoRoute处理器的URL解码 - 移除dashboard.go文件中的BOM字符 - 添加Vite构建配置确保文件名格式正确
This commit is contained in:
+11
-2
@@ -6,6 +6,7 @@ import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"verification-platform-backend/internal/config"
|
||||
@@ -263,8 +264,12 @@ func setupEmbeddedFrontend(r *gin.Engine) {
|
||||
|
||||
r.GET("/assets/*filepath", func(c *gin.Context) {
|
||||
filepath := c.Param("filepath")
|
||||
decodedPath, err := url.PathUnescape(filepath)
|
||||
if err != nil {
|
||||
decodedPath = filepath
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=31536000, immutable")
|
||||
c.FileFromFS("assets/"+filepath, http.FS(distFS))
|
||||
c.FileFromFS("assets/"+decodedPath, http.FS(distFS))
|
||||
})
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
@@ -274,7 +279,11 @@ func setupEmbeddedFrontend(r *gin.Engine) {
|
||||
}
|
||||
|
||||
path := strings.TrimPrefix(c.Request.URL.Path, "/")
|
||||
if f, err := distFS.Open(path); err == nil {
|
||||
decodedPath, err := url.PathUnescape(path)
|
||||
if err != nil {
|
||||
decodedPath = path
|
||||
}
|
||||
if f, err := distFS.Open(decodedPath); err == nil {
|
||||
f.Close()
|
||||
c.FileFromFS(c.Request.URL.Path, http.FS(distFS))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user