~metalune/simplytranslate-devel

web: Make /api/translate also work with GET v1 APPLIED

fattalion: 1
 Make /api/translate also work with GET

 1 files changed, 10 insertions(+), 7 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~metalune/simplytranslate-devel/patches/27454/mbox | git am -3
Learn more about email & git

[PATCH web] Make /api/translate also work with GET Export this patch

We can make it POST-only later, but clients like SimplyTranslate CLI
still use GET.
---
 main.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/main.py b/main.py
index 5ddab85..6db2b0a 100644
--- a/main.py
+++ b/main.py
@@ -68,14 +68,17 @@ async def translate(from_language, to_language, input_text):
    )


@app.route("/api/translate/", methods=["POST"])
@app.route("/api/translate/", methods=["GET", "POST"])
async def api_translate():
    form = await request.form

    engine_name = request.args.get("engine")
    text = form.get("text")
    from_language = form.get("from")
    to_language = form.get("to")
    if request.method == "POST":
        args = await request.form
    elif request.method == "GET":
        args = request.args

    engine_name = args.get("engine")
    text = args.get("text")
    from_language = args.get("from")
    to_language = args.get("to")

    engine = get_engine(engine_name, engines, engines[0])

-- 
2.34.1