make state endpoint more solid

This commit is contained in:
henryruhs committed 2026-09-24 00:19:48 +02:00
1 parent 4bc621fa62
commit 435a0b2db4
2 files changed
+5 -4

No files matched your search

+2 -1
View File
@@ -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')
+3 -3
View File
@@ -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