dlna: count the number of children in the response to BrowseMetadata

This commit is contained in:
Dan Walters 2019-09-15 12:33:45 -05:00 committed by Nick Craig-Wood
parent ab89e93968
commit 2f10472df3
2 changed files with 15 additions and 4 deletions

View File

@ -77,10 +77,17 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
} }
if fileInfo.IsDir() { if fileInfo.IsDir() {
children, err := cds.readContainer(cdsObject, host)
if err != nil {
return nil, err
}
obj.Class = "object.container.storageFolder" obj.Class = "object.container.storageFolder"
obj.Title = fileInfo.Name() obj.Title = fileInfo.Name()
ret = upnpav.Container{Object: obj} return upnpav.Container{
return Object: obj,
ChildCount: len(children),
}, nil
} }
if !fileInfo.Mode().IsRegular() { if !fileInfo.Mode().IsRegular() {

View File

@ -3,6 +3,7 @@ package dlna
import ( import (
"context" "context"
"fmt" "fmt"
"html"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
@ -118,6 +119,9 @@ func TestContentDirectoryBrowseMetadata(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode) assert.Equal(t, http.StatusOK, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, string(body), "&lt;container ") // expect a <container> element
require.NotContains(t, string(body), "&lt;item ") require.Contains(t, string(body), html.EscapeString("<container "))
require.NotContains(t, string(body), html.EscapeString("<item "))
// with a non-zero childCount
require.Contains(t, string(body), html.EscapeString(`childCount="1"`))
} }