mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 11:02:21 -05:00
Fixed issues with cached images not loading correctly, major speed improvement!
Fixed issues with saving config.
This commit is contained in:
parent
22fd3086ae
commit
785c2d37db
@ -17,9 +17,7 @@
|
|||||||
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
import inspect
|
|
||||||
|
|
||||||
import threading
|
|
||||||
import traceback
|
import traceback
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@ -75,10 +73,10 @@ except ImportError:
|
|||||||
|
|
||||||
from Cheetah.Template import Template
|
from Cheetah.Template import Template
|
||||||
|
|
||||||
from functools import wraps
|
|
||||||
from tornado.routes import route
|
from tornado.routes import route
|
||||||
from tornado.web import RequestHandler, HTTPError, authenticated, addslash, removeslash, asynchronous
|
from tornado.httpclient import AsyncHTTPClient
|
||||||
from tornado.gen import coroutine, Task
|
from tornado.web import RequestHandler, HTTPError, authenticated, asynchronous
|
||||||
|
from tornado.gen import coroutine
|
||||||
from tornado.concurrent import run_on_executor
|
from tornado.concurrent import run_on_executor
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
@ -226,13 +224,12 @@ class BaseHandler(RequestHandler):
|
|||||||
class WebHandler(BaseHandler):
|
class WebHandler(BaseHandler):
|
||||||
executor = ThreadPoolExecutor(10)
|
executor = ThreadPoolExecutor(10)
|
||||||
|
|
||||||
@addslash
|
|
||||||
@coroutine
|
@coroutine
|
||||||
@asynchronous
|
@asynchronous
|
||||||
@authenticated
|
@authenticated
|
||||||
def get(self, route, *args, **kwargs):
|
def get(self, route, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
route = route.strip('/') or 'index'
|
route = route.strip('/').replace('.', '_') or 'index'
|
||||||
|
|
||||||
# get route
|
# get route
|
||||||
method = getattr(self, route)
|
method = getattr(self, route)
|
||||||
@ -244,27 +241,28 @@ class WebHandler(BaseHandler):
|
|||||||
|
|
||||||
@run_on_executor
|
@run_on_executor
|
||||||
def async_worker(self, method, callback):
|
def async_worker(self, method, callback):
|
||||||
# get params
|
|
||||||
kwargs = self.request.arguments
|
kwargs = self.request.arguments
|
||||||
for arg, value in kwargs.items():
|
for arg, value in kwargs.items():
|
||||||
if len(value) == 1:
|
if len(value) == 1:
|
||||||
kwargs[arg] = value[0]
|
kwargs[arg] = value[0]
|
||||||
|
|
||||||
# get result
|
|
||||||
try:
|
try:
|
||||||
result = ek.ss(method(**kwargs)).encode('utf-8', 'xmlcharrefreplace')
|
callback(method(**kwargs))
|
||||||
|
except Exception as e:
|
||||||
|
callback()
|
||||||
|
|
||||||
|
def async_done(self, result=None):
|
||||||
|
try:
|
||||||
|
if result:
|
||||||
|
result = ek.ss(result).encode('utf-8', 'xmlcharrefreplace')
|
||||||
except:
|
except:
|
||||||
result = method(**kwargs)
|
pass
|
||||||
|
|
||||||
# finish result
|
if result:
|
||||||
callback(result)
|
self.write(result)
|
||||||
|
self.finish()
|
||||||
|
|
||||||
def async_done(self, result):
|
# post and get use same method
|
||||||
# write response
|
|
||||||
self.write(result)
|
|
||||||
self.finish()
|
|
||||||
|
|
||||||
# link post to get
|
|
||||||
post = get
|
post = get
|
||||||
|
|
||||||
class LoginHandler(BaseHandler):
|
class LoginHandler(BaseHandler):
|
||||||
@ -394,12 +392,12 @@ class WebRoot(WebHandler):
|
|||||||
if ek.ek(os.path.isfile, image_file_name):
|
if ek.ek(os.path.isfile, image_file_name):
|
||||||
image_path = image_file_name
|
image_path = image_file_name
|
||||||
|
|
||||||
from mimetypes import MimeTypes
|
#from mimetypes import MimeTypes
|
||||||
|
#mime_type, encoding = MimeTypes().guess_type(image_path)
|
||||||
|
#self.set_header('Content-Type', mime_type)
|
||||||
|
|
||||||
mime_type, encoding = MimeTypes().guess_type(image_path)
|
static_image_path = image_path.replace(sickbeard.CACHE_DIR, '')
|
||||||
self.set_header('Content-Type', mime_type)
|
self.redirect(static_image_path)
|
||||||
with file(image_path, 'rb') as img:
|
|
||||||
return img.read()
|
|
||||||
|
|
||||||
def setHomeLayout(self, layout):
|
def setHomeLayout(self, layout):
|
||||||
|
|
||||||
|
@ -12,13 +12,11 @@ from tornado.httpserver import HTTPServer
|
|||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
from tornado.routes import route
|
from tornado.routes import route
|
||||||
|
|
||||||
|
|
||||||
class MultiStaticFileHandler(StaticFileHandler):
|
class MultiStaticFileHandler(StaticFileHandler):
|
||||||
def initialize(self, paths):
|
def initialize(self, paths):
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
|
|
||||||
def set_extra_headers(self, path):
|
|
||||||
self.set_header("Cache-control", "no-store, no-cache, must-revalidate, max-age=0")
|
|
||||||
|
|
||||||
def get(self, path, include_body=True):
|
def get(self, path, include_body=True):
|
||||||
for staticPath in self.paths:
|
for staticPath in self.paths:
|
||||||
try:
|
try:
|
||||||
@ -28,7 +26,7 @@ class MultiStaticFileHandler(StaticFileHandler):
|
|||||||
if e.status_code == 404:
|
if e.status_code == 404:
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
self.set_status(404)
|
raise HTTPError(404)
|
||||||
|
|
||||||
|
|
||||||
class SRWebServer(threading.Thread):
|
class SRWebServer(threading.Thread):
|
||||||
@ -96,16 +94,14 @@ class SRWebServer(threading.Thread):
|
|||||||
|
|
||||||
# Main Handlers
|
# Main Handlers
|
||||||
self.app.add_handlers('.*$', [
|
self.app.add_handlers('.*$', [
|
||||||
(r'/', RedirectHandler, {"url": self.options['web_root'] + '/home/'}),
|
|
||||||
(r'%s(/?)' % self.options['api_root'], ApiHandler),
|
(r'%s(/?)' % self.options['api_root'], ApiHandler),
|
||||||
(r'%s/getkey(/?)' % self.options['web_root'], KeyHandler),
|
(r'%s/getkey(/?)' % self.options['web_root'], KeyHandler),
|
||||||
(r'%s/api/builder' % self.options['web_root'], RedirectHandler,
|
(r'%s/api/builder' % self.options['web_root'], RedirectHandler, {"url": self.options['web_root'] + '/apibuilder'}),
|
||||||
{"url": self.options['web_root'] + '/apibuilder/'}),
|
|
||||||
(r'%s/login(/?)' % self.options['web_root'], LoginHandler),
|
(r'%s/login(/?)' % self.options['web_root'], LoginHandler),
|
||||||
(r'%s/logout(/?)' % self.options['web_root'], LogoutHandler),
|
(r'%s/logout(/?)' % self.options['web_root'], LogoutHandler),
|
||||||
] + route.get_routes(self.options['web_root']))
|
] + route.get_routes(self.options['web_root']))
|
||||||
|
|
||||||
# Static Path Handlers
|
# Static Handlers
|
||||||
self.app.add_handlers(".*$", [
|
self.app.add_handlers(".*$", [
|
||||||
(r'%s/(favicon\.ico)' % self.options['web_root'], MultiStaticFileHandler,
|
(r'%s/(favicon\.ico)' % self.options['web_root'], MultiStaticFileHandler,
|
||||||
{'paths': [os.path.join(self.options['data_root'], 'images/ico/favicon.ico')]}),
|
{'paths': [os.path.join(self.options['data_root'], 'images/ico/favicon.ico')]}),
|
||||||
|
Loading…
Reference in New Issue
Block a user