Changed to a http:app. Massively based on github.com/tkem/mopidy-mobile
This commit is contained in:
parent
c655f12131
commit
b94db6bfcc
@ -4,7 +4,6 @@ import os
|
||||
|
||||
from mopidy import config, ext
|
||||
|
||||
|
||||
__version__ = '1.0.4'
|
||||
|
||||
|
||||
@ -23,7 +22,14 @@ class MusicBoxExtension(ext.Extension):
|
||||
return schema
|
||||
|
||||
def setup(self, registry):
|
||||
registry.add('http:static', {
|
||||
'name': self.ext_name,
|
||||
'path': os.path.join(os.path.dirname(__file__), 'static'),
|
||||
})
|
||||
registry.add('http:app', {'name': self.ext_name, 'factory': self.factory})
|
||||
|
||||
def factory(self, config, core):
|
||||
from tornado.web import RedirectHandler
|
||||
from .web import IndexHandler, StaticHandler
|
||||
path = os.path.join(os.path.dirname(__file__), 'static')
|
||||
return [
|
||||
(r'/', RedirectHandler, {'url': 'index.html'}),
|
||||
(r'/(index.html)', IndexHandler, {'config': config, 'path': path}),
|
||||
(r'/(.*)', StaticHandler, {'path': path})
|
||||
]
|
||||
|
||||
48
mopidy_musicbox_webclient/web.py
Normal file
48
mopidy_musicbox_webclient/web.py
Normal file
@ -0,0 +1,48 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import string
|
||||
|
||||
import tornado.web
|
||||
|
||||
from . import MusicBoxExtension
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StaticHandler(tornado.web.StaticFileHandler):
|
||||
|
||||
def get(self, path, *args, **kwargs):
|
||||
version = self.get_argument('v', None)
|
||||
if version:
|
||||
logger.debug('Get static resource for %s?v=%s', path, version)
|
||||
else:
|
||||
logger.debug('Get static resource for %s', path)
|
||||
return super(StaticHandler, self).get(path, *args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def get_version(cls, settings, path):
|
||||
return MusicBoxExtension.version
|
||||
|
||||
|
||||
class IndexHandler(tornado.web.RequestHandler):
|
||||
|
||||
def initialize(self, config, path):
|
||||
ext_config = config[MusicBoxExtension.ext_name]
|
||||
self.__dict = {
|
||||
'version': MusicBoxExtension.version
|
||||
}
|
||||
self.__path = path
|
||||
self.__title = string.Template('MusicBox on $hostname')
|
||||
|
||||
def get(self, path):
|
||||
return self.render('index.html', title=self.get_title(), **self.__dict)
|
||||
|
||||
def get_title(self):
|
||||
hostname, sep, port = self.request.host.rpartition(':')
|
||||
if not sep or not port.isdigit():
|
||||
hostname, port = self.request.host, '80'
|
||||
return self.__title.safe_substitute(hostname=hostname, port=port)
|
||||
|
||||
def get_template_path(self):
|
||||
return self.__path
|
||||
Loading…
Reference in New Issue
Block a user