From cb11dfc6b13ed05eda0365e76a1adf1e38eef228 Mon Sep 17 00:00:00 2001 From: Robert George Date: Fri, 29 Sep 2023 13:49:52 -0700 Subject: [PATCH] Allow json submission to /suggest --- libretranslate/app.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libretranslate/app.py b/libretranslate/app.py index 39ad1ec..5b7a925 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -1038,10 +1038,17 @@ def create_app(args): if not args.suggestions: abort(403, description=_("Suggestions are disabled on this server.")) - q = request.values.get("q") - s = request.values.get("s") - source_lang = request.values.get("source") - target_lang = request.values.get("target") + if request.is_json: + json = get_json_dict(request) + q = json.get("q") + s = json.get("s") + source_lang = json.get("source") + target_lang = json.get("target") + else: + q = request.values.get("q") + s = request.values.get("s") + source_lang = request.values.get("source") + target_lang = request.values.get("target") if not q: abort(400, description=_("Invalid request: missing %(name)s parameter", name='q'))