mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-06 05:16:38 +08:00
fix spa fallback for library routes
This commit is contained in:
@@ -31,6 +31,7 @@ logs/
|
|||||||
.tmp-deploy-smoke-cache/
|
.tmp-deploy-smoke-cache/
|
||||||
.tmp-deploy-cache/
|
.tmp-deploy-cache/
|
||||||
.tmp-deploy-server.*
|
.tmp-deploy-server.*
|
||||||
|
.tmp-live-server.*
|
||||||
.mediastation.pid
|
.mediastation.pid
|
||||||
*.log
|
*.log
|
||||||
*.db
|
*.db
|
||||||
|
|||||||
@@ -200,6 +200,9 @@ func setNoCacheHeaders(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func shouldBypassSPAFallback(path string) bool {
|
func shouldBypassSPAFallback(path string) bool {
|
||||||
|
if isFrontendLibraryRoute(path) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
lower := strings.ToLower(path)
|
lower := strings.ToLower(path)
|
||||||
for _, exact := range []string{
|
for _, exact := range []string{
|
||||||
"/emby",
|
"/emby",
|
||||||
@@ -233,6 +236,33 @@ func shouldBypassSPAFallback(path string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isFrontendLibraryRoute(path string) bool {
|
||||||
|
const prefix = "/library/"
|
||||||
|
if !strings.HasPrefix(path, prefix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
id := strings.TrimPrefix(path, prefix)
|
||||||
|
if strings.Contains(id, "/") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(id) != 36 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i, ch := range id {
|
||||||
|
switch i {
|
||||||
|
case 8, 13, 18, 23:
|
||||||
|
if ch != '-' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func newLogger(cfg *config.Config) (*zap.Logger, error) {
|
func newLogger(cfg *config.Config) (*zap.Logger, error) {
|
||||||
if cfg.App.Debug {
|
if cfg.App.Debug {
|
||||||
return zap.NewDevelopment()
|
return zap.NewDevelopment()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func TestServeSPANoCachesIndexAndServesRoutes(t *testing.T) {
|
|||||||
router := gin.New()
|
router := gin.New()
|
||||||
serveSPA(router, webDir)
|
serveSPA(router, webDir)
|
||||||
|
|
||||||
for _, path := range []string{"/", "/login", "/media/abc"} {
|
for _, path := range []string{"/", "/login", "/library/e1c3507e-2878-40ae-a0e1-6b6e44b7fa7a", "/media/abc"} {
|
||||||
req := httptest.NewRequest(http.MethodGet, path, nil)
|
req := httptest.NewRequest(http.MethodGet, path, nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
router.ServeHTTP(w, req)
|
router.ServeHTTP(w, req)
|
||||||
@@ -76,6 +76,7 @@ func TestServeSPAServesAssetsImmutableAndBypassesAPIRoutes(t *testing.T) {
|
|||||||
"/api/missing",
|
"/api/missing",
|
||||||
"/emby",
|
"/emby",
|
||||||
"/emby/missing",
|
"/emby/missing",
|
||||||
|
"/Library/VirtualFolders",
|
||||||
"/Startup/Configuration",
|
"/Startup/Configuration",
|
||||||
"/QuickConnect/Enabled",
|
"/QuickConnect/Enabled",
|
||||||
"/embywebsocket",
|
"/embywebsocket",
|
||||||
|
|||||||
Reference in New Issue
Block a user