Skip to content

Commit

Permalink
fix: asset lookup when one asset path is prefix of another
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Feb 14, 2024
1 parent 0557d4f commit 37c44bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Make --playurl work for general paths
- Derive and insert contentType if missing
- Remove any mehd box from init segment
- Asset lookup for case where one asset path is prefix of another

## [1.1.1] - 2024-01-19

Expand Down
2 changes: 1 addition & 1 deletion cmd/livesim2/app/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type assetMgr struct {
// findAsset finds the asset by matching the uri with all assets paths.
func (am *assetMgr) findAsset(uri string) (*asset, bool) {
for assetPath := range am.assets {
if strings.HasPrefix(uri, assetPath) {
if uri == assetPath || strings.HasPrefix(uri, assetPath+"/") {
return am.assets[assetPath], true
}
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/livesim2/app/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ func TestLoadAsset(t *testing.T) {
assert.Equal(t, 720_000, rep.duration())
assert.Equal(t, 8000, asset.LoopDurMS)
}

func TestAssetLookupForNameOverlap(t *testing.T) {
am := assetMgr{}
am.assets = make(map[string]*asset)
am.assets["assets/testpic_2s"] = &asset{AssetPath: "assets/testpic_2s"}
am.assets["assets/testpic_2s_1"] = &asset{AssetPath: "assets/testpic_2s_1"}
uri := "assets/testpic_2s_1/rep1/init.mp4"
a, ok := am.findAsset(uri)
require.True(t, ok)
require.Equal(t, "assets/testpic_2s_1", a.AssetPath)
}
10 changes: 5 additions & 5 deletions cmd/livesim2/app/handler_livesim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,28 @@ func TestFetches(t *testing.T) {
}{
{
desc: "mpd",
url: "testpic_2s_thumbs/Manifest.mpd",
url: "testpic_2s/Manifest_thumbs.mpd",
params: "",
wantedStatusCode: http.StatusOK,
wantedContentType: `application/dash+xml`,
},
{
desc: "thumbnail image",
url: "testpic_2s_thumbs/thumbs/300.jpg?nowMS=610000",
url: "testpic_2s/thumbs/300.jpg?nowMS=610000",
params: "",
wantedStatusCode: http.StatusOK,
wantedContentType: `image/jpeg`,
},
{
desc: "imsc1 image subtitle",
url: "testpic_2s_imsc1/imsc1_img_en/300.m4s?nowMS=610000",
url: "testpic_2s/imsc1_img_en/300.m4s?nowMS=610000",
params: "",
wantedStatusCode: http.StatusOK,
wantedContentType: `application/mp4`,
},
{
desc: "imsc1 text subtitle",
url: "testpic_2s_imsc1/imsc1_txt_sv/300.m4s?nowMS=610000",
url: "testpic_2s/imsc1_txt_sv/300.m4s?nowMS=610000",
params: "",
wantedStatusCode: http.StatusOK,
wantedContentType: `application/mp4`,
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestFetches(t *testing.T) {
},
{
desc: "thumbnail image too early",
url: "testpic_2s_thumbs/thumbs/300.jpg?nowMS=510000",
url: "testpic_2s/thumbs/300.jpg?nowMS=510000",
params: "",
wantedStatusCode: 425,
wantedContentType: `image/jpeg`,
Expand Down

0 comments on commit 37c44bd

Please sign in to comment.