mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 03:06:38 +08:00
23d1fbfddb
Root cause: display-only cloud library filtering was reused by scan jobs, merged cloud mounts could be skipped, and OpenList listing relied on WebDAV/first-page behavior that could cap huge directories around 100 items. Cloud scans also let new items consume probe budget before existing rows with missing track/artwork metadata.\n\nChanges:\n- split display filtering from scannable cloud filtering so merged cloud mounts still scan\n- add OpenList API pagination with WebDAV fallback\n- prioritize existing cloud media missing metadata before new imports\n- restrict automatic cloud sync to one successful 19:00-21:00 daily window and keep manual scan immediate\n- disable startup cloud full-scan by default, with an explicit opt-in setting\n- improve Emby/cloud playback compatibility and cache/search/test coverage from the continued work
110 lines
3.2 KiB
Go
110 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestServeSPANoCachesIndexAndServesRoutes(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
webDir := t.TempDir()
|
|
if err := os.MkdirAll(filepath.Join(webDir, "assets"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(webDir, "index.html"), []byte("<html><div id=\"root\"></div></html>"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(webDir, "assets", "app.js"), []byte("console.log('ok')"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(webDir, "favicon.svg"), []byte("<svg></svg>"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
router := gin.New()
|
|
serveSPA(router, webDir)
|
|
|
|
for _, path := range []string{"/", "/login", "/media/abc"} {
|
|
req := httptest.NewRequest(http.MethodGet, path, nil)
|
|
w := httptest.NewRecorder()
|
|
router.ServeHTTP(w, req)
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("%s status = %d, want 200", path, w.Code)
|
|
}
|
|
if got := w.Header().Get("Cache-Control"); !strings.Contains(got, "no-store") {
|
|
t.Fatalf("%s Cache-Control = %q, want no-store", path, got)
|
|
}
|
|
if !strings.Contains(w.Body.String(), "root") {
|
|
t.Fatalf("%s did not serve index.html: %q", path, w.Body.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestServeSPAServesAssetsImmutableAndBypassesAPIRoutes(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
webDir := t.TempDir()
|
|
if err := os.MkdirAll(filepath.Join(webDir, "assets"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(webDir, "index.html"), []byte("index"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(webDir, "assets", "app.js"), []byte("console.log('ok')"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
router := gin.New()
|
|
serveSPA(router, webDir)
|
|
|
|
assetReq := httptest.NewRequest(http.MethodGet, "/assets/app.js", nil)
|
|
assetResp := httptest.NewRecorder()
|
|
router.ServeHTTP(assetResp, assetReq)
|
|
if assetResp.Code != http.StatusOK {
|
|
t.Fatalf("asset status = %d, want 200", assetResp.Code)
|
|
}
|
|
if got := assetResp.Header().Get("Cache-Control"); !strings.Contains(got, "immutable") {
|
|
t.Fatalf("asset Cache-Control = %q, want immutable", got)
|
|
}
|
|
|
|
for _, path := range []string{
|
|
"/api/missing",
|
|
"/emby",
|
|
"/emby/missing",
|
|
"/Startup/Configuration",
|
|
"/QuickConnect/Enabled",
|
|
"/embywebsocket",
|
|
} {
|
|
req := httptest.NewRequest(http.MethodGet, path, nil)
|
|
resp := httptest.NewRecorder()
|
|
router.ServeHTTP(resp, req)
|
|
if resp.Code != http.StatusNotFound {
|
|
t.Fatalf("%s fallback status = %d, want 404", path, resp.Code)
|
|
}
|
|
if strings.Contains(resp.Body.String(), "index") {
|
|
t.Fatalf("%s should not serve SPA index: %q", path, resp.Body.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestServeSPAMissingIndexReportsExplicit404(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
router := gin.New()
|
|
serveSPA(router, t.TempDir())
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
w := httptest.NewRecorder()
|
|
router.ServeHTTP(w, req)
|
|
if w.Code != http.StatusNotFound {
|
|
t.Fatalf("status = %d, want 404", w.Code)
|
|
}
|
|
if !strings.Contains(w.Body.String(), "web UI not found") {
|
|
t.Fatalf("body = %q, want explicit missing UI message", w.Body.String())
|
|
}
|
|
}
|