mirror of
https://github.com/facefusion/facefusion.git
synced 2026-11-12 05:19:57 +01:00
make state endpoint more solid
This commit is contained in:
1 parent
4bc621fa62
commit
435a0b2db4
2 files changed
+5
-4
No files matched your search
@@ -34,9 +34,10 @@ async def set_state(request : Request) -> Response:
|
||||
'message': translator.get('invalid_state_key', 'facefusion.apis')
|
||||
}, status_code = HTTP_400_BAD_REQUEST)
|
||||
|
||||
choices = capability_store.get_api_capability_set().get(key).get('choices')
|
||||
__value__ = cast_argument_value(key, value)
|
||||
|
||||
if not validate_argument_value(key, __value__):
|
||||
if not validate_argument_value(key, __value__) or choices and __value__ not in choices:
|
||||
return JSONResponse(
|
||||
{
|
||||
'message': translator.get('invalid_state_value', 'facefusion.apis')
|
||||
|
||||
@@ -12,6 +12,9 @@ def validate_argument_value(key : StateKey, value : StateValue) -> bool:
|
||||
if State.__annotations__.get(key) is bool:
|
||||
return isinstance(value, bool)
|
||||
|
||||
if State.__annotations__.get(key) is list:
|
||||
return isinstance(value, list)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -23,9 +26,6 @@ def cast_argument_value(key : StateKey, value : StateValue) -> StateValue:
|
||||
return cast_float(value)
|
||||
|
||||
if State.__annotations__.get(key) is bool:
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
|
||||
return cast_bool(value)
|
||||
|
||||
return value
|
||||
Reference in new issue
Block a user