dlna: move root descriptor xml template to the static assets
Reduce binary size.
This commit is contained in:
parent
5f07bbf8ce
commit
c49a71f438
4 changed files with 121 additions and 83 deletions
File diff suppressed because one or more lines are too long
|
@ -2,3 +2,35 @@
|
||||||
// The "go:generate" directive compiles static assets by running assets_generate.go
|
// The "go:generate" directive compiles static assets by running assets_generate.go
|
||||||
|
|
||||||
package data
|
package data
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rclone/rclone/fs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetTemplate returns the rootDesc XML template
|
||||||
|
func GetTemplate() (tpl *template.Template, err error) {
|
||||||
|
templateFile, err := Assets.Open("rootDesc.xml.tmpl")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "get template open")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer fs.CheckClose(templateFile, &err)
|
||||||
|
|
||||||
|
templateBytes, err := ioutil.ReadAll(templateFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "get template read")
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateString = string(templateBytes)
|
||||||
|
|
||||||
|
tpl, err = template.New("rootDesc").Parse(templateString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "get template parse")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
66
cmd/serve/dlna/data/static/rootDesc.xml.tmpl
Normal file
66
cmd/serve/dlna/data/static/rootDesc.xml.tmpl
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<root xmlns="urn:schemas-upnp-org:device-1-0"
|
||||||
|
xmlns:dlna="urn:schemas-dlna-org:device-1-0"
|
||||||
|
xmlns:sec="http://www.sec.co.kr/dlna">
|
||||||
|
<specVersion>
|
||||||
|
<major>1</major>
|
||||||
|
<minor>0</minor>
|
||||||
|
</specVersion>
|
||||||
|
<device>
|
||||||
|
<deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>
|
||||||
|
<friendlyName>{{.FriendlyName}}</friendlyName>
|
||||||
|
<manufacturer>rclone (rclone.org)</manufacturer>
|
||||||
|
<manufacturerURL>https://rclone.org/</manufacturerURL>
|
||||||
|
<modelDescription>rclone</modelDescription>
|
||||||
|
<modelName>rclone</modelName>
|
||||||
|
<modelNumber>{{.ModelNumber}}</modelNumber>
|
||||||
|
<modelURL>https://rclone.org/</modelURL>
|
||||||
|
<serialNumber>00000000</serialNumber>
|
||||||
|
<UDN>{{.RootDeviceUUID}}</UDN>
|
||||||
|
<dlna:X_DLNACAP/>
|
||||||
|
<dlna:X_DLNADOC>DMS-1.50</dlna:X_DLNADOC>
|
||||||
|
<dlna:X_DLNADOC>M-DMS-1.50</dlna:X_DLNADOC>
|
||||||
|
<sec:ProductCap>smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec</sec:ProductCap>
|
||||||
|
<sec:X_ProductCap>smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec</sec:X_ProductCap>
|
||||||
|
<iconList>
|
||||||
|
<icon>
|
||||||
|
<mimetype>image/png</mimetype>
|
||||||
|
<width>48</width>
|
||||||
|
<height>48</height>
|
||||||
|
<depth>8</depth>
|
||||||
|
<url>/static/rclone-48x48.png</url>
|
||||||
|
</icon>
|
||||||
|
<icon>
|
||||||
|
<mimetype>image/png</mimetype>
|
||||||
|
<width>120</width>
|
||||||
|
<height>120</height>
|
||||||
|
<depth>8</depth>
|
||||||
|
<url>/static/rclone-120x120.png</url>
|
||||||
|
</icon>
|
||||||
|
</iconList>
|
||||||
|
<serviceList>
|
||||||
|
<service>
|
||||||
|
<serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType>
|
||||||
|
<serviceId>urn:upnp-org:serviceId:ContentDirectory</serviceId>
|
||||||
|
<SCPDURL>/static/ContentDirectory.xml</SCPDURL>
|
||||||
|
<controlURL>/ctl</controlURL>
|
||||||
|
<eventSubURL></eventSubURL>
|
||||||
|
</service>
|
||||||
|
<service>
|
||||||
|
<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>
|
||||||
|
<serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
|
||||||
|
<SCPDURL>/static/ConnectionManager.xml</SCPDURL>
|
||||||
|
<controlURL>/ctl</controlURL>
|
||||||
|
<eventSubURL></eventSubURL>
|
||||||
|
</service>
|
||||||
|
<service>
|
||||||
|
<serviceType>urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1</serviceType>
|
||||||
|
<serviceId>urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar</serviceId>
|
||||||
|
<SCPDURL>/static/X_MS_MediaReceiverRegistrar.xml</SCPDURL>
|
||||||
|
<controlURL>/ctl</controlURL>
|
||||||
|
<eventSubURL></eventSubURL>
|
||||||
|
</service>
|
||||||
|
</serviceList>
|
||||||
|
<presentationURL>/</presentationURL>
|
||||||
|
</device>
|
||||||
|
</root>
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dms_dlna "github.com/anacrolix/dms/dlna"
|
dms_dlna "github.com/anacrolix/dms/dlna"
|
||||||
|
@ -156,85 +155,18 @@ func (s *server) ModelNumber() string {
|
||||||
return fs.Version
|
return fs.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template used to generate the root device XML descriptor.
|
|
||||||
//
|
|
||||||
// Due to the use of namespaces and various subtleties with device compatibility,
|
|
||||||
// it turns out to be easier to use a template than to marshal XML.
|
|
||||||
//
|
|
||||||
// For rendering, it is passed the server object for context.
|
|
||||||
var rootDescTmpl = template.Must(template.New("rootDesc").Parse(`<?xml version="1.0"?>
|
|
||||||
<root xmlns="urn:schemas-upnp-org:device-1-0"
|
|
||||||
xmlns:dlna="urn:schemas-dlna-org:device-1-0"
|
|
||||||
xmlns:sec="http://www.sec.co.kr/dlna">
|
|
||||||
<specVersion>
|
|
||||||
<major>1</major>
|
|
||||||
<minor>0</minor>
|
|
||||||
</specVersion>
|
|
||||||
<device>
|
|
||||||
<deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>
|
|
||||||
<friendlyName>{{.FriendlyName}}</friendlyName>
|
|
||||||
<manufacturer>rclone (rclone.org)</manufacturer>
|
|
||||||
<manufacturerURL>https://rclone.org/</manufacturerURL>
|
|
||||||
<modelDescription>rclone</modelDescription>
|
|
||||||
<modelName>rclone</modelName>
|
|
||||||
<modelNumber>{{.ModelNumber}}</modelNumber>
|
|
||||||
<modelURL>https://rclone.org/</modelURL>
|
|
||||||
<serialNumber>00000000</serialNumber>
|
|
||||||
<UDN>{{.RootDeviceUUID}}</UDN>
|
|
||||||
<dlna:X_DLNACAP/>
|
|
||||||
<dlna:X_DLNADOC>DMS-1.50</dlna:X_DLNADOC>
|
|
||||||
<dlna:X_DLNADOC>M-DMS-1.50</dlna:X_DLNADOC>
|
|
||||||
<sec:ProductCap>smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec</sec:ProductCap>
|
|
||||||
<sec:X_ProductCap>smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec</sec:X_ProductCap>
|
|
||||||
<iconList>
|
|
||||||
<icon>
|
|
||||||
<mimetype>image/png</mimetype>
|
|
||||||
<width>48</width>
|
|
||||||
<height>48</height>
|
|
||||||
<depth>8</depth>
|
|
||||||
<url>/static/rclone-48x48.png</url>
|
|
||||||
</icon>
|
|
||||||
<icon>
|
|
||||||
<mimetype>image/png</mimetype>
|
|
||||||
<width>120</width>
|
|
||||||
<height>120</height>
|
|
||||||
<depth>8</depth>
|
|
||||||
<url>/static/rclone-120x120.png</url>
|
|
||||||
</icon>
|
|
||||||
</iconList>
|
|
||||||
<serviceList>
|
|
||||||
<service>
|
|
||||||
<serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType>
|
|
||||||
<serviceId>urn:upnp-org:serviceId:ContentDirectory</serviceId>
|
|
||||||
<SCPDURL>/static/ContentDirectory.xml</SCPDURL>
|
|
||||||
<controlURL>/ctl</controlURL>
|
|
||||||
<eventSubURL></eventSubURL>
|
|
||||||
</service>
|
|
||||||
<service>
|
|
||||||
<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>
|
|
||||||
<serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
|
|
||||||
<SCPDURL>/static/ConnectionManager.xml</SCPDURL>
|
|
||||||
<controlURL>/ctl</controlURL>
|
|
||||||
<eventSubURL></eventSubURL>
|
|
||||||
</service>
|
|
||||||
<service>
|
|
||||||
<serviceType>urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1</serviceType>
|
|
||||||
<serviceId>urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar</serviceId>
|
|
||||||
<SCPDURL>/static/X_MS_MediaReceiverRegistrar.xml</SCPDURL>
|
|
||||||
<controlURL>/ctl</controlURL>
|
|
||||||
<eventSubURL></eventSubURL>
|
|
||||||
</service>
|
|
||||||
</serviceList>
|
|
||||||
<presentationURL>/</presentationURL>
|
|
||||||
</device>
|
|
||||||
</root>`))
|
|
||||||
|
|
||||||
// Renders the root device descriptor.
|
// Renders the root device descriptor.
|
||||||
func (s *server) rootDescHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *server) rootDescHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
buffer := new(bytes.Buffer)
|
tmpl, err := data.GetTemplate()
|
||||||
err := rootDescTmpl.Execute(buffer, s)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
serveError(s, w, "Failed to create root descriptor XML", err)
|
serveError(s, w, "Failed to load root descriptor template", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
err = tmpl.Execute(buffer, s)
|
||||||
|
if err != nil {
|
||||||
|
serveError(s, w, "Failed to render root descriptor XML", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue