stop the update_ui method from calling core methods when the client isn't connected
make the current http request available to exported methods via a __request__ global that gets set before each call
This commit is contained in:
parent
2de8069c9f
commit
6334820a5d
|
@ -138,7 +138,7 @@ class JSON(resource.Resource, component.Component):
|
||||||
def _on_client_disconnect(self, *args):
|
def _on_client_disconnect(self, *args):
|
||||||
component.get("Web.PluginManager").stop()
|
component.get("Web.PluginManager").stop()
|
||||||
|
|
||||||
def _exec_local(self, method, params):
|
def _exec_local(self, method, params, request):
|
||||||
"""
|
"""
|
||||||
Handles executing all local methods.
|
Handles executing all local methods.
|
||||||
"""
|
"""
|
||||||
|
@ -151,7 +151,9 @@ class JSON(resource.Resource, component.Component):
|
||||||
elif method in self._local_methods:
|
elif method in self._local_methods:
|
||||||
# This will eventually process methods that the server adds
|
# This will eventually process methods that the server adds
|
||||||
# and any plugins.
|
# and any plugins.
|
||||||
return self._local_methods[method](*params)
|
meth = self._local_methods[method]
|
||||||
|
meth.func_globals['__request__'] = request
|
||||||
|
return meth(*params)
|
||||||
raise JSONException("Unknown system method")
|
raise JSONException("Unknown system method")
|
||||||
|
|
||||||
def _exec_remote(self, method, params):
|
def _exec_remote(self, method, params):
|
||||||
|
@ -169,25 +171,26 @@ class JSON(resource.Resource, component.Component):
|
||||||
"""
|
"""
|
||||||
request_id = None
|
request_id = None
|
||||||
try:
|
try:
|
||||||
request = json.loads(request)
|
request.json = json.loads(request.json)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise JSONException("JSON not decodable")
|
raise JSONException("JSON not decodable")
|
||||||
|
|
||||||
if "method" not in request or "id" not in request or \
|
if "method" not in request.json or "id" not in request.json or \
|
||||||
"params" not in request:
|
"params" not in request.json:
|
||||||
raise JSONException("Invalid JSON request")
|
raise JSONException("Invalid JSON request")
|
||||||
|
|
||||||
method, params = request["method"], request["params"]
|
method, params = request.json["method"], request.json["params"]
|
||||||
request_id = request["id"]
|
request_id = request.json["id"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if method.startswith("system."):
|
if method.startswith("system."):
|
||||||
return self._exec_local(method, params), request_id
|
return self._exec_local(method, params, request), request_id
|
||||||
elif method in self._local_methods:
|
elif method in self._local_methods:
|
||||||
return self._exec_local(method, params), request_id
|
return self._exec_local(method, params, request), request_id
|
||||||
elif method in self._remote_methods:
|
elif method in self._remote_methods:
|
||||||
return self._exec_remote(method, params), request_id
|
return self._exec_remote(method, params), request_id
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
log.error("Error calling method `%s`", method)
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
d.callback(None)
|
d.callback(None)
|
||||||
|
@ -215,7 +218,7 @@ class JSON(resource.Resource, component.Component):
|
||||||
"""
|
"""
|
||||||
log.debug("json-request: %s", request.json)
|
log.debug("json-request: %s", request.json)
|
||||||
response = {"result": None, "error": None, "id": None}
|
response = {"result": None, "error": None, "id": None}
|
||||||
d, response["id"] = self._handle_request(request.json)
|
d, response["id"] = self._handle_request(request)
|
||||||
d.addCallback(self._on_rpc_request_finished, response, request)
|
d.addCallback(self._on_rpc_request_finished, response, request)
|
||||||
d.addErrback(self._on_rpc_request_failed, response, request)
|
d.addErrback(self._on_rpc_request_failed, response, request)
|
||||||
return d
|
return d
|
||||||
|
@ -369,17 +372,17 @@ class WebApi(JSONComponent):
|
||||||
:returns: The torrent and ui information.
|
:returns: The torrent and ui information.
|
||||||
:rtype: dictionary
|
:rtype: dictionary
|
||||||
"""
|
"""
|
||||||
|
d = Deferred()
|
||||||
ui_info = {
|
ui_info = {
|
||||||
"torrents": None,
|
"torrents": None,
|
||||||
"filters": None,
|
"filters": None,
|
||||||
"stats": None
|
"stats": None
|
||||||
}
|
}
|
||||||
|
|
||||||
d = Deferred()
|
if not client.connected():
|
||||||
|
d.callback(ui_info)
|
||||||
log.info("Updating ui with keys '%r' and filters '%r'", keys,
|
return d
|
||||||
filter_dict)
|
|
||||||
|
|
||||||
def got_stats(stats):
|
def got_stats(stats):
|
||||||
ui_info["stats"] = stats
|
ui_info["stats"] = stats
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue