From 9e58b6db01a34e5ac0fe0b63f94aea529f8e83a9 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Wed, 18 Nov 2026 13:51:54 +0100 Subject: [PATCH] feat(media): forward WMV live transcode options to CarrierNode streamMediaIdentifier now forwards only the quality and start query parameters to CarrierNode, so browser-unplayable WMV/ASF video can stream as a seekable live H.264 copy. Other query parameters are not forwarded, and audio-only playback is unchanged. Co-Authored-By: Claude Haiku 5.5 --- backend/media/media.go | 18 +++++++++++++++++- backend/media/media_test.go | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/backend/media/media.go b/backend/media/media.go index 2e1cd5e..e92aa66 100644 --- a/backend/media/media.go +++ b/backend/media/media.go @@ -135,7 +135,23 @@ func (c *Service) streamMediaIdentifier(w http.ResponseWriter, r *http.Request, writeError(w, http.StatusNotFound, "media not found") return } - c.carrierNode.Proxy(w, r, "/media/"+upstream) + c.carrierNode.Proxy(w, r, streamUpstreamPath(upstream, r.URL.Query())) +} + +// streamUpstreamPath is the CarrierNode request path for a stream. CarrierNode answers with a live +// H.264 copy when the query carries quality (a height) and start (seconds), which is how browsers get +// containers they cannot decode. Those two parameters are the only ones forwarded. +func streamUpstreamPath(upstream string, query url.Values) string { + forward := url.Values{} + for _, key := range []string{"quality", "start"} { + if value := strings.TrimSpace(query.Get(key)); value != "" { + forward.Set(key, value) + } + } + if len(forward) == 0 { + return "/media/" + upstream + } + return "/media/" + upstream + "?" + forward.Encode() } func (c *Service) thumbnailMediaByQuery(w http.ResponseWriter, r *http.Request) { diff --git a/backend/media/media_test.go b/backend/media/media_test.go index 4c1a8bb..b71a5c0 100644 --- a/backend/media/media_test.go +++ b/backend/media/media_test.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "net/http/httptest" + "net/url" "strings" "testing" @@ -124,3 +125,20 @@ func TestOnlyModeratorsCanSeeHiddenMedia(t *testing.T) { } } } + +func TestStreamUpstreamPathForwardsOnlyLiveTranscodeOptions(t *testing.T) { + for _, tc := range []struct { + name string + query url.Values + want string + }{ + {"plain stream", url.Values{"mediaKey": {"abc"}}, "/media/Videos/clip.mp4"}, + {"blank options are dropped", url.Values{"quality": {" "}, "start": {""}}, "/media/Videos/clip.mp4"}, + {"quality and start are forwarded", url.Values{"mediaKey": {"abc"}, "quality": {"1080"}, "start": {" 12.5 "}}, "/media/Videos/clip.mp4?quality=1080&start=12.5"}, + {"quality alone", url.Values{"quality": {"720"}}, "/media/Videos/clip.mp4?quality=720"}, + } { + if got := streamUpstreamPath("Videos/clip.mp4", tc.query); got != tc.want { + t.Errorf("%s: streamUpstreamPath() = %q, want %q", tc.name, got, tc.want) + } + } +}