From fa7a10e5cf8ef7f5229425b32a81b60cc2e806db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Einarson?= Date: Tue, 15 Aug 2023 15:08:08 +0200 Subject: [PATCH] fix: allow jpg and jpeg extensions (for thumbnails) --- cmd/livesim2/app/handler_livesim.go | 2 +- cmd/livesim2/app/handler_livesim_test.go | 51 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/cmd/livesim2/app/handler_livesim.go b/cmd/livesim2/app/handler_livesim.go index 5037c2f..1fb4956 100644 --- a/cmd/livesim2/app/handler_livesim.go +++ b/cmd/livesim2/app/handler_livesim.go @@ -82,7 +82,7 @@ func (s *Server) livesimHandlerFunc(w http.ResponseWriter, r *http.Request) { http.Error(w, msg, http.StatusInternalServerError) return } - case ".mp4", ".m4s", ".cmfv", "cmfa", "cmft": + case ".mp4", ".m4s", ".cmfv", ".cmfa", ".cmft", ".jpg", ".jpeg", ".m4v", ".m4a": segmentPart := strings.TrimPrefix(contentPart, a.AssetPath) // includes heading / err = writeSegment(r.Context(), w, log, cfg, s.assetMgr.vodFS, a, segmentPart[1:], nowMS, s.textTemplates) if err != nil { diff --git a/cmd/livesim2/app/handler_livesim_test.go b/cmd/livesim2/app/handler_livesim_test.go index 6e44e1c..5163e16 100644 --- a/cmd/livesim2/app/handler_livesim_test.go +++ b/cmd/livesim2/app/handler_livesim_test.go @@ -78,3 +78,54 @@ func TestParamToMPD(t *testing.T) { }) } } + +// TestFetches tests fetching of segments and other content. +func TestFetches(t *testing.T) { + cfg := ServerConfig{ + VodRoot: "testdata/assets", + TimeoutS: 0, + LogFormat: logging.LogDiscard, + } + _, err := logging.InitZerolog(cfg.LogLevel, cfg.LogFormat) + require.NoError(t, err) + server, err := SetupServer(context.Background(), &cfg) + require.NoError(t, err) + ts := httptest.NewServer(server.Router) + defer ts.Close() + testCases := []struct { + desc string + url string + params string + wantedStatusCode int + wantedContentType string + }{ + { + desc: "mpd", + url: "testpic_2s_thumbs/Manifest.mpd", + params: "", + wantedStatusCode: http.StatusOK, + wantedContentType: `application/dash+xml`, + }, + { + desc: "thumbnail image", + url: "testpic_2s_thumbs/thumbs/300.jpg?nowMS=610000", + params: "", + wantedStatusCode: http.StatusOK, + wantedContentType: `image/jpeg`, + }, + } + + for _, tc := range testCases { + t.Run(tc.desc, func(t *testing.T) { + totURL := "/livesim2/" + tc.params + tc.url + resp, body := testFullRequest(t, ts, "GET", totURL, nil) + require.Equal(t, tc.wantedStatusCode, resp.StatusCode) + if tc.wantedStatusCode != http.StatusOK { + return + } + require.Greater(t, len(body), 0, "no body") + gotContentType := resp.Header.Get("Content-Type") + require.Equal(t, tc.wantedContentType, gotContentType) + }) + } +}