|
|
@ -1,4 +1,5 @@ |
|
|
|
from couchpotato.core.helpers.request import getParams |
|
|
|
from couchpotato.core.logger import CPLog |
|
|
|
from functools import wraps |
|
|
|
from threading import Thread |
|
|
|
from tornado.gen import coroutine |
|
|
@ -6,8 +7,12 @@ from tornado.web import RequestHandler, asynchronous |
|
|
|
import json |
|
|
|
import threading |
|
|
|
import tornado |
|
|
|
import traceback |
|
|
|
import urllib |
|
|
|
|
|
|
|
log = CPLog(__name__) |
|
|
|
|
|
|
|
|
|
|
|
api = {} |
|
|
|
api_locks = {} |
|
|
|
api_nonblock = {} |
|
|
@ -41,7 +46,11 @@ class NonBlockHandler(RequestHandler): |
|
|
|
if self.request.connection.stream.closed(): |
|
|
|
return |
|
|
|
|
|
|
|
try: |
|
|
|
self.write(response) |
|
|
|
except: |
|
|
|
log.error('Failed doing nonblock request: %s', (traceback.format_exc())) |
|
|
|
self.write({'success': False, 'error': 'Failed returning results'}) |
|
|
|
|
|
|
|
def on_connection_close(self): |
|
|
|
|
|
|
@ -70,6 +79,8 @@ class ApiHandler(RequestHandler): |
|
|
|
|
|
|
|
api_locks[route].acquire() |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
kwargs = {} |
|
|
|
for x in self.request.arguments: |
|
|
|
kwargs[x] = urllib.unquote(self.get_argument(x)) |
|
|
@ -98,6 +109,10 @@ class ApiHandler(RequestHandler): |
|
|
|
else: |
|
|
|
self.write(result) |
|
|
|
|
|
|
|
except: |
|
|
|
log.error('Failed doing api request "%s": %s', (route, traceback.format_exc())) |
|
|
|
self.write({'success': False, 'error': 'Failed returning results'}) |
|
|
|
|
|
|
|
api_locks[route].release() |
|
|
|
|
|
|
|
def addApiView(route, func, static = False, docs = None, **kwargs): |
|
|
|