aboutsummaryrefslogtreecommitdiff
path: root/modules/rest_api.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-02-19 19:45:26 +0000
committerGravatar jesopo2019-02-19 19:45:26 +0000
commit2691fa52e6a40224e588d732a9a92a12b1cddf3c (patch)
tree7cac51ed7750a077a03a768dd86e78afc7f705f8 /modules/rest_api.py
parentMerge pull request #42 from Zarthus/patch-1 (diff)
signature
Do database-related work on UI thread (rest_api.py)
Diffstat (limited to 'modules/rest_api.py')
-rw-r--r--modules/rest_api.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/rest_api.py b/modules/rest_api.py
index 25a214e7..b17875cc 100644
--- a/modules/rest_api.py
+++ b/modules/rest_api.py
@@ -33,6 +33,12 @@ class Handler(http.server.BaseHTTPRequestHandler):
self.end_headers()
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):
path, endpoint, args = self._path_data()
headers = utils.CaseInsensitiveDict(dict(self.headers.items()))
@@ -48,7 +54,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
hook = hooks[0]
authenticated = hook.get_kwarg("authenticated", True)
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", [])
if key_setting:
@@ -70,7 +76,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
if not event_response == None:
content_type = "application/json"
- if _bot.get_setting("rest-api-minify", False):
+ if minify:
response = json.dumps(event_response,
sort_keys=True, separators=(",", ":"))
else: