move meta objects to getTorrentMeta

This commit is contained in:
nikk gitanes
2021-09-13 22:28:50 +03:00
parent 5f30aa4c27
commit 136284bff2
2 changed files with 29 additions and 32 deletions

View File

@@ -11,10 +11,8 @@ import (
"time"
"github.com/anacrolix/dms/dlna/dms"
"github.com/anacrolix/dms/upnpav"
"server/log"
"server/torr"
"server/web/pages/template"
)
@@ -129,34 +127,6 @@ func onBrowse(path, rootObjectPath, host, userAgent string) (ret []interface{},
}
func onBrowseMeta(path string, rootObjectPath string, host, userAgent string) (ret interface{}, err error) {
if path == "/" {
rootObj := upnpav.Object{
ID: "0",
ParentID: "-1",
Restricted: 1,
Searchable: 1,
Title: "TorrServer",
Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container.storageFolder",
}
// add Root Object
ret = upnpav.Container{Object: rootObj, ChildCount: 1}
return
} else if path == "/TR" {
// TR Object Meta
trObj := upnpav.Object{
ID: "%2FTR",
ParentID: "0",
Restricted: 1,
Searchable: 1,
Title: "Torrents",
Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container.storageFolder",
}
vol := len(torr.ListTorrent())
ret = upnpav.Container{Object: trObj, ChildCount: vol}
return
}
ret = getTorrentMeta(path, host)
if ret == nil {
err = fmt.Errorf("meta not found")

View File

@@ -73,7 +73,7 @@ func getTorrents() (ret []interface{}) {
Class: "object.container.storageFolder",
Date: upnpav.Timestamp{Time: time.Now()},
}
cnt := upnpav.Container{Object: obj, ChildCount: 1}
cnt := upnpav.Container{Object: obj, ChildCount: 0}
ret = append(ret, cnt)
}
return
@@ -129,7 +129,34 @@ func getTorrentMeta(path, host string) (ret interface{}) {
}
// Meta object
if isHashPath(path) {
if path == "/" {
// root object meta
rootObj := upnpav.Object{
ID: "0",
ParentID: "-1",
Restricted: 1,
Searchable: 1,
Title: "TorrServer",
Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container.storageFolder",
}
meta := upnpav.Container{Object: rootObj, ChildCount: 1}
return meta
} else if path == "/TR" {
// TR Object Meta
trObj := upnpav.Object{
ID: "%2FTR",
ParentID: "0",
Restricted: 1,
Searchable: 1,
Title: "Torrents",
Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container.storageFolder",
}
vol := len(torrs)
meta := upnpav.Container{Object: trObj, ChildCount: vol}
return meta
} else if isHashPath(path) {
// hash object meta
obj := upnpav.Object{
ID: "%2F" + torr.TorrentSpec.InfoHash.HexString(),