Fix Emby playback routes and stream compatibility

This commit is contained in:
ShukeBta
2026-05-28 16:00:09 +08:00
parent e93eb40f4e
commit 68a5a1e3c0
8 changed files with 1143 additions and 56 deletions
+27 -2
View File
@@ -19,6 +19,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
@@ -149,8 +150,9 @@ func serveSPA(r *gin.Engine, webDir string) {
r.StaticFile("/favicon.ico", filepath.Join(webDir, "favicon.ico"))
r.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
// Do not swallow API or WebSocket routes; let them 404 naturally.
if len(path) >= 5 && path[:5] == "/api/" {
// Do not swallow API / Emby compatibility routes; clients expect JSON
// or 404, not the React index.html fallback.
if shouldBypassSPAFallback(path) {
c.Status(http.StatusNotFound)
return
}
@@ -158,6 +160,29 @@ func serveSPA(r *gin.Engine, webDir string) {
})
}
func shouldBypassSPAFallback(path string) bool {
lower := strings.ToLower(path)
for _, prefix := range []string{
"/api/",
"/emby/",
"/system/",
"/users/",
"/items/",
"/shows/",
"/library/",
"/videos/",
"/sessions/",
"/displaypreferences/",
"/branding/",
"/localization/",
} {
if strings.HasPrefix(lower, prefix) {
return true
}
}
return false
}
func newLogger(cfg *config.Config) (*zap.Logger, error) {
if cfg.App.Debug {
return zap.NewDevelopment()