Skip to content

Commit

Permalink
fix: allow jpg and jpeg extensions (for thumbnails)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Aug 15, 2023
1 parent b5d7678 commit fa7a10e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/livesim2/app/handler_livesim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 51 additions & 0 deletions cmd/livesim2/app/handler_livesim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

0 comments on commit fa7a10e

Please sign in to comment.