diff options
| author | 2019-09-20 10:41:52 +0100 | |
|---|---|---|
| committer | 2019-09-20 10:41:52 +0100 | |
| commit | cf65614832167f5e0701339529b4f16252a37bc4 (patch) | |
| tree | 4053bcf88c5e956c9ff2ab801199e8a92d77360f /modules | |
| parent | use source Hostmask from multiline batch (diff) | |
| signature | ||
support path-arg variables in url_for
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/rest_api.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/rest_api.py b/modules/rest_api.py index 076148f6..17700369 100644 --- a/modules/rest_api.py +++ b/modules/rest_api.py @@ -79,8 +79,9 @@ class Handler(http.server.BaseHTTPRequestHandler): return _bot.get_setting("rest-api-minify", False) def _url_for(self, headers): - return lambda route, endpoint, get_params={}: _module._url_for( - route, endpoint, get_params, headers.get("Host", None)) + return (lambda route, endpoint, args=[], get_params={}: + _module._url_for(route, endpoint, args, get_params, + headers.get("Host", None)) def _handle(self, method, path, endpoint, args): headers = utils.CaseInsensitiveDict(dict(self.headers.items())) @@ -199,7 +200,8 @@ class Module(ModuleManager.BaseModule): }) event["stdout"].write("New API key ('%s'): %s" % (comment, api_key)) - def _url_for(self, route, endpoint, get_params={}, host_override=None): + def _url_for(self, route, endpoint, args=[], get_params={}, + host_override=None): host = host_override or self.bot.get_setting("rest-api-host", None) host, _, port = host.partition(":") @@ -208,9 +210,13 @@ class Module(ModuleManager.BaseModule): host = "%s:%s" % (host, port) if host: + args_str = "" + if args: + args_str = "/%s" % "/".join(args) get_params_str = "" if get_params: get_params_str = "?%s" % urllib.parse.urlencode(get_params) - return "%s/%s/%s%s" % (host, route, endpoint, get_params_str) + return "%s/%s/%s%s%s" % (host, route, endpoint, args_str, + get_params_str) else: return None |
