fix media workflows and download organization

This commit is contained in:
ShukeBta
2026-06-26 08:42:16 +08:00
parent 0da96f7e4e
commit 65adca04df
102 changed files with 4063 additions and 437 deletions
+57
View File
@@ -159,6 +159,63 @@ func TestServeFileRedirectsCloudMediaForVideoStreamMode(t *testing.T) {
}
}
func TestServeFileRedirectsCloudMediaExternalHTTPSTRMURL(t *testing.T) {
repos := newStreamTestRepo(t)
target := "https://cdn.example.test/Movie.mkv?sign=direct"
if err := repos.DB.Create(&model.Media{
Base: model.Base{ID: "cloud-http"},
Title: "Cloud HTTP",
Path: "cloud://openlist/Movie.mkv",
STRMURL: target,
}).Error; err != nil {
t.Fatal(err)
}
svc := NewStreamService(&config.Config{}, zap.NewNop(), repos, nil)
req := httptest.NewRequest(http.MethodGet, "http://nas.local:18080/api/stream/cloud-http?token=jwt123", nil)
w := httptest.NewRecorder()
if err := svc.ServeFile(w, req, "cloud-http"); err != nil {
t.Fatalf("external HTTP STRM target should redirect: %v", err)
}
if w.Code != http.StatusFound {
t.Fatalf("status = %d, want 302", w.Code)
}
loc := w.Header().Get("Location")
if loc != target {
t.Fatalf("Location = %q, want %q", loc, target)
}
if strings.Contains(loc, "jwt123") || strings.Contains(loc, "media_id=") {
t.Fatalf("external direct link must not receive internal auth query, got %q", loc)
}
}
func TestServeFileRedirectsLocalSTRMFileTargetByDefault(t *testing.T) {
repos := newStreamTestRepo(t)
target := "https://cdn.example.test/LocalMovie.mkv?sign=direct"
if err := repos.DB.Create(&model.Media{
Base: model.Base{ID: "local-strm"},
Title: "Local STRM",
Path: "D:/media/LocalMovie.strm",
Container: "strm",
STRMURL: target,
}).Error; err != nil {
t.Fatal(err)
}
svc := NewStreamService(&config.Config{}, zap.NewNop(), repos, nil)
req := httptest.NewRequest(http.MethodGet, "http://nas.local:18080/api/stream/local-strm?token=jwt123", nil)
w := httptest.NewRecorder()
if err := svc.ServeFile(w, req, "local-strm"); err != nil {
t.Fatalf("local .strm media should redirect to its target: %v", err)
}
if w.Code != http.StatusFound {
t.Fatalf("status = %d, want 302", w.Code)
}
if loc := w.Header().Get("Location"); loc != target {
t.Fatalf("Location = %q, want %q", loc, target)
}
}
func TestCloudPlaybackModeUsesExplicitModeBeforeLegacySTRMFlag(t *testing.T) {
repos := newStreamTestRepo(t)
if got := CloudPlaybackMode(t.Context(), repos); got != CloudPlaybackModeRedirectProxy {