forked from mirrors/LibreTranslate
updated argos, validate input JSON dict
This commit is contained in:
parent
a86442f23c
commit
b8818ff14e
2 changed files with 10 additions and 4 deletions
12
app/app.py
12
app/app.py
|
@ -11,6 +11,12 @@ DetectorFactory.seed = 0 # deterministic
|
|||
|
||||
api_keys_db = None
|
||||
|
||||
def get_json_dict(request):
|
||||
d = request.get_json()
|
||||
if not isinstance(d, dict):
|
||||
abort(400, description="Invalid JSON format")
|
||||
return d
|
||||
|
||||
def get_remote_address():
|
||||
if request.headers.getlist("X-Forwarded-For"):
|
||||
ip = request.headers.getlist("X-Forwarded-For")[0]
|
||||
|
@ -29,7 +35,7 @@ def get_routes_limits(default_req_limit, api_keys_db):
|
|||
|
||||
if api_keys_db:
|
||||
if request.is_json:
|
||||
json = request.get_json()
|
||||
json = get_json_dict(request)
|
||||
api_key = json.get('api_key')
|
||||
else:
|
||||
api_key = request.values.get("api_key")
|
||||
|
@ -232,7 +238,7 @@ def create_app(args):
|
|||
"""
|
||||
|
||||
if request.is_json:
|
||||
json = request.get_json()
|
||||
json = get_json_dict(request)
|
||||
q = json.get('q')
|
||||
source_lang = json.get('source')
|
||||
target_lang = json.get('target')
|
||||
|
@ -371,7 +377,7 @@ def create_app(args):
|
|||
description: Reason for slow down
|
||||
"""
|
||||
if request.is_json:
|
||||
json = request.get_json()
|
||||
json = get_json_dict(request)
|
||||
q = json.get('q')
|
||||
else:
|
||||
q = request.values.get("q")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
argostranslate==1.1.2
|
||||
argostranslate==1.1.3
|
||||
Flask==1.1.2
|
||||
flask-swagger==0.2.14
|
||||
flask-swagger-ui==3.36.0
|
||||
|
|
Loading…
Reference in a new issue