serve dlna: fix invalid dc:date for containers
Containers (directories) never had their Date field set, producing <dc:date>0001-01-01</dc:date> (Go's zero time) in DIDL-Lite metadata. This invalid date can confuse strict DLNA clients. Set the dc:date to the directory's modification time, and as a safety net, omit the dc:date element entirely when the timestamp is zero. See #9346
This commit is contained in:
@@ -44,6 +44,7 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
|
||||
if fileInfo.IsDir() {
|
||||
obj.Class = "object.container.storageFolder"
|
||||
obj.Title = fileInfo.Name()
|
||||
obj.Date = upnpav.Timestamp{Time: fileInfo.ModTime()}
|
||||
childCount, err := cds.countChildren(cdsObject.Path)
|
||||
if err != nil {
|
||||
fs.Debugf(cds, "error counting children of %s: %v", cdsObject.Path, err)
|
||||
|
||||
@@ -58,7 +58,11 @@ type Timestamp struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// MarshalXML formats the Timestamp per DIDL-Lite spec
|
||||
// MarshalXML formats the Timestamp per DIDL-Lite spec.
|
||||
// Zero times are omitted to avoid producing invalid dates like "0001-01-01".
|
||||
func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
if t.IsZero() {
|
||||
return nil
|
||||
}
|
||||
return e.EncodeElement(t.Format("2006-01-02"), start)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user