Do database-related work on UI thread (rest_api.py)
This commit is contained in:
parent
2093640f07
commit
2691fa52e6
1 changed files with 8 additions and 2 deletions
|
@ -33,6 +33,12 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(data.encode("utf8"))
|
self.wfile.write(data.encode("utf8"))
|
||||||
|
|
||||||
|
def _get_settings(self):
|
||||||
|
key = params.get("key", None)
|
||||||
|
key_setting = _bot.get_setting("api-key-%s" % key, {})
|
||||||
|
minify = _bot.get_setting("rest-api-minify", False):
|
||||||
|
return [key_setting, minify]
|
||||||
|
|
||||||
def _handle(self, method):
|
def _handle(self, method):
|
||||||
path, endpoint, args = self._path_data()
|
path, endpoint, args = self._path_data()
|
||||||
headers = utils.CaseInsensitiveDict(dict(self.headers.items()))
|
headers = utils.CaseInsensitiveDict(dict(self.headers.items()))
|
||||||
|
@ -48,7 +54,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
hook = hooks[0]
|
hook = hooks[0]
|
||||||
authenticated = hook.get_kwarg("authenticated", True)
|
authenticated = hook.get_kwarg("authenticated", True)
|
||||||
key = params.get("key", None)
|
key = params.get("key", None)
|
||||||
key_setting = _bot.get_setting("api-key-%s" % key, {})
|
key_setting, minify = _bot.trigger(self._get_settings)
|
||||||
permissions = key_setting.get("permissions", [])
|
permissions = key_setting.get("permissions", [])
|
||||||
|
|
||||||
if key_setting:
|
if key_setting:
|
||||||
|
@ -70,7 +76,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
if not event_response == None:
|
if not event_response == None:
|
||||||
content_type = "application/json"
|
content_type = "application/json"
|
||||||
if _bot.get_setting("rest-api-minify", False):
|
if minify:
|
||||||
response = json.dumps(event_response,
|
response = json.dumps(event_response,
|
||||||
sort_keys=True, separators=(",", ":"))
|
sort_keys=True, separators=(",", ":"))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue