This commit is contained in:
2026-08-24 16:40:48 +03:00
parent f7e99516bf
commit 32abb8bf0a
73 changed files with 12364 additions and 9292 deletions
@@ -81,6 +81,41 @@ def _validate_response_check(data):
}
def _validate_latch_reset(data):
if data is None:
return None
if not isinstance(data, dict):
abort(400, "latchReset must be an object")
enabled = bool(data.get("enabled", False))
if not enabled:
return {"enabled": False}
reset_url = (data.get("resetUrl") or "").strip()
if not reset_url:
abort(400, "latchReset.resetUrl is required when enabled")
success_match = (data.get("successMatch") or "OK").strip() or "OK"
result = {
"enabled": True,
"resetUrl": reset_url,
"successMatch": success_match,
}
if data.get("fireAndForget"):
result["fireAndForget"] = True
return result
def _apply_button_latch_reset(btn, data):
if "latchReset" not in data:
return btn
lr = _validate_latch_reset(data.get("latchReset"))
if lr is None:
btn.pop("latchReset", None)
else:
btn["latchReset"] = lr
return btn
def _apply_button_action(action, data):
action["type"] = data.get("actionType", action.get("type", "http_get"))
action["url"] = data.get("url", action.get("url", ""))
@@ -88,6 +123,17 @@ def _apply_button_action(action, data):
action["headers"] = data["headers"]
if "body" in data:
action["body"] = data["body"]
if "timeoutMs" in data:
try:
timeout_ms = int(data["timeoutMs"])
except (TypeError, ValueError):
abort(400, "timeoutMs must be an integer")
if timeout_ms < 1000 or timeout_ms > 600000:
abort(400, "timeoutMs must be between 1000 and 600000")
if timeout_ms == 7000:
action.pop("timeoutMs", None)
else:
action["timeoutMs"] = timeout_ms
if "responseCheck" in data:
rc = _validate_response_check(data.get("responseCheck"))
if rc is None:
@@ -148,6 +194,7 @@ def api_add_button():
},
"color": data.get("color", "#7b007b"),
}
_apply_button_latch_reset(btn, data)
cfg.setdefault("buttons", []).append(btn)
save_config(cfg)
return jsonify(btn)
@@ -180,6 +227,7 @@ def api_update_button(bid):
trigger.setdefault("holdMs", 800)
if "color" in data:
b["color"] = data["color"]
_apply_button_latch_reset(b, data)
save_config(cfg)
return jsonify(b)
abort(404)