Revert "change meta response"

This reverts commit 44f1cfbd9d.
This commit is contained in:
nikk gitanes
2021-09-13 19:25:40 +03:00
parent 46bd8d0a8d
commit 6d81b419ab
2 changed files with 34 additions and 43 deletions

View File

@@ -10,8 +10,10 @@ import (
"time" "time"
"github.com/anacrolix/dms/dlna/dms" "github.com/anacrolix/dms/dlna/dms"
"github.com/anacrolix/dms/upnpav"
"server/log" "server/log"
"server/torr"
"server/web/pages/template" "server/web/pages/template"
) )
@@ -119,6 +121,34 @@ func onBrowse(path, rootObjectPath, host, userAgent string) (ret []interface{},
} }
func onBrowseMeta(path string, rootObjectPath string, host, userAgent string) (ret interface{}, err error) { 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) ret = getTorrentMeta(path, host)
if ret == nil { if ret == nil {
err = fmt.Errorf("meta not found") err = fmt.Errorf("meta not found")

View File

@@ -114,36 +114,6 @@ func getTorrent(path, host string) (ret []interface{}) {
} }
func getTorrentMeta(path, host string) (ret interface{}) { func getTorrentMeta(path, host string) (ret interface{}) {
if path=="/" {
rootObj := upnpav.Object{
ID: "0",
ParentID: "-1",
Restricted: 1,
Searchable: 1,
Title: "TorrServer",
Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container",
}
// add Root Object
meta := upnpav.Container{Object: rootObj}
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",
}
//vol := len(torr.ListTorrent())
meta := upnpav.Container{Object: trObj}
return meta
}
// find torrent without load // find torrent without load
torrs := torr.ListTorrent() torrs := torr.ListTorrent()
var torr *torr.Torrent var torr *torr.Torrent
@@ -166,15 +136,11 @@ func getTorrentMeta(path, host string) (ret interface{}) {
Restricted: 1, Restricted: 1,
Title: torr.Title, Title: torr.Title,
Date: upnpav.Timestamp{Time: time.Now()}, Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container",
} }
meta := upnpav.Container{Object: obj} meta := upnpav.Container{Object: obj, ChildCount: 1}
return meta return meta
} else if filepath.Base(path) == "LD" { } else if filepath.Base(path) == "LD" {
parent := url.PathEscape(filepath.Dir(path)) parent := url.PathEscape(filepath.Dir(path))
if settings.BTsets.EnableDebug {
log.TLogln("getTorrentMeta parent for LD", parent)
}
// LD object meta // LD object meta
obj := upnpav.Object{ obj := upnpav.Object{
ID: parent + "%2FLD", ID: parent + "%2FLD",
@@ -183,17 +149,13 @@ func getTorrentMeta(path, host string) (ret interface{}) {
Searchable: 1, Searchable: 1,
Title: "Load Torrents", Title: "Load Torrents",
Date: upnpav.Timestamp{Time: time.Now()}, Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container",
} }
meta := upnpav.Container{Object: obj} meta := upnpav.Container{Object: obj, ChildCount: 1}
return meta return meta
} else { } else {
file := filepath.Base(path) file := filepath.Base(path)
id := url.PathEscape(path) id := url.PathEscape(path)
parent := url.PathEscape(filepath.Dir(path)) parent := url.PathEscape(filepath.Dir(path))
if settings.BTsets.EnableDebug {
log.TLogln("getTorrentMeta id:", id, "parent:", parent)
}
// file object meta // file object meta
obj := upnpav.Object{ obj := upnpav.Object{
ID: id, ID: id,
@@ -202,12 +164,11 @@ func getTorrentMeta(path, host string) (ret interface{}) {
Searchable: 1, Searchable: 1,
Title: file, Title: file,
Date: upnpav.Timestamp{Time: time.Now()}, Date: upnpav.Timestamp{Time: time.Now()},
Class: "object.container",
} }
meta := upnpav.Container{Object: obj} meta := upnpav.Container{Object: obj, ChildCount: 1}
return meta return meta
} }
// for error response
return nil return nil
} }