fix cloud library mounts and artwork caching

This commit is contained in:
ShukeBta
2026-06-10 20:43:42 +08:00
parent 0bf983cec8
commit fd0428ee7d
36 changed files with 1469 additions and 140 deletions
+33
View File
@@ -13,6 +13,7 @@ import (
"go.uber.org/zap"
"github.com/ShukeBta/MediaStationGo/internal/config"
"github.com/ShukeBta/MediaStationGo/internal/service/cloud"
)
func TestImageProxyServesLocalImagePath(t *testing.T) {
@@ -115,6 +116,38 @@ func TestImageProxyCachesFailedRemoteImageFetch(t *testing.T) {
}
}
func TestImageProxyCachesCloudResolvedImage(t *testing.T) {
var calls int32
proxy := NewImageProxy(&config.Config{Cache: config.CacheConfig{CacheDir: filepath.Join(t.TempDir(), "cache")}}, zap.NewNop())
proxy.client = &http.Client{Transport: imageRoundTripFunc(func(req *http.Request) (*http.Response, error) {
atomic.AddInt32(&calls, 1)
return &http.Response{
StatusCode: http.StatusOK,
Status: "200 OK",
Header: http.Header{"Content-Type": []string{"image/png"}},
Body: io.NopCloser(strings.NewReader(string(transparent1x1PNG))),
Request: req,
}, nil
})}
link := &cloud.DirectLink{URL: "http://cloud-provider.invalid/poster.png"}
for i := 0; i < 2; i++ {
rec := httptest.NewRecorder()
if err := proxy.ServeCloudResolved(t.Context(), rec, httptest.NewRequest(http.MethodGet, "/api/cloud/play/openlist?ref=poster.png", nil), "openlist:poster.png", link); err != nil {
t.Fatal(err)
}
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200", rec.Code)
}
if got := rec.Header().Get("Cache-Control"); got != imageBrowserCacheControl {
t.Fatalf("Cache-Control = %q, want %q", got, imageBrowserCacheControl)
}
}
if got := atomic.LoadInt32(&calls); got != 1 {
t.Fatalf("upstream calls = %d, want 1 due to cloud image cache", got)
}
}
type imageRoundTripFunc func(*http.Request) (*http.Response, error)
func (f imageRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {