Cap sound and stream URL fields at 2048 chars

This commit is contained in:
Jage9
2026-02-22 03:52:46 -05:00
parent c7ba23f371
commit 2b7bb04c12
4 changed files with 28 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
// Maintainer-controlled web client version.
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
window.CHGRID_WEB_VERSION = "2026.02.22 R145";
window.CHGRID_WEB_VERSION = "2026.02.22 R146";
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
window.CHGRID_TIME_ZONE = "America/Detroit";

View File

@@ -86,8 +86,16 @@ ITEM_TYPE_TOOLTIPS: dict[ItemType, str] = {
}
GLOBAL_ITEM_PROPERTY_METADATA: dict[str, dict[str, object]] = {
"useSound": {"valueType": "sound", "tooltip": "One-shot sound played when this item is used successfully."},
"emitSound": {"valueType": "sound", "tooltip": "Looping sound emitted from this item on the grid."},
"useSound": {
"valueType": "sound",
"tooltip": "One-shot sound played when this item is used successfully.",
"maxLength": 2048,
},
"emitSound": {
"valueType": "sound",
"tooltip": "Looping sound emitted from this item on the grid.",
"maxLength": 2048,
},
"useCooldownMs": {"valueType": "number", "tooltip": "Global cooldown in milliseconds between uses for this item type."},
"emitRange": {"valueType": "number", "tooltip": "Maximum distance in squares where emitted audio can be heard."},
"directional": {"valueType": "boolean", "tooltip": "Whether emitted audio favors the item's facing direction."},

View File

@@ -44,7 +44,7 @@ EFFECT_OPTIONS: tuple[str, ...] = ("reverb", "echo", "flanger", "high_pass", "lo
PROPERTY_METADATA: dict[str, dict[str, object]] = {
"title": {"valueType": "text", "tooltip": "Display name spoken and shown for this item.", "maxLength": 80},
"streamUrl": {"valueType": "text", "tooltip": "Audio stream URL used by this radio."},
"streamUrl": {"valueType": "text", "tooltip": "Audio stream URL used by this radio.", "maxLength": 2048},
"enabled": {"valueType": "boolean", "tooltip": "Turns playback on or off for this radio."},
"mediaVolume": {
"valueType": "number",
@@ -75,6 +75,8 @@ def validate_update(item: WorldItem, next_params: dict) -> dict:
"""Validate and normalize radio params."""
stream_url = str(next_params.get("streamUrl", "")).strip()
if len(stream_url) > 2048:
raise ValueError("streamUrl must be 2048 characters or less.")
previous_stream_url = str(item.params.get("streamUrl", "")).strip()
next_params["streamUrl"] = stream_url

View File

@@ -81,8 +81,16 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = {
"tooltip": "Amount for emit effect.",
"range": {"min": 0, "max": 100, "step": 0.1},
},
"useSound": {"valueType": "sound", "tooltip": "Sound played on use. Filename assumes sounds folder, or use full URL."},
"emitSound": {"valueType": "sound", "tooltip": "Looping emitted sound. Filename assumes sounds folder, or use full URL."},
"useSound": {
"valueType": "sound",
"tooltip": "Sound played on use. Filename assumes sounds folder, or use full URL.",
"maxLength": 2048,
},
"emitSound": {
"valueType": "sound",
"tooltip": "Looping emitted sound. Filename assumes sounds folder, or use full URL.",
"maxLength": 2048,
},
}
@@ -169,6 +177,10 @@ def validate_update(item: WorldItem, next_params: dict) -> dict:
next_params["useSound"] = _normalize_sound_value(next_params.get("useSound", item.params.get("useSound", "")))
next_params["emitSound"] = _normalize_sound_value(next_params.get("emitSound", item.params.get("emitSound", "")))
if len(next_params["useSound"]) > 2048:
raise ValueError("useSound must be 2048 characters or less.")
if len(next_params["emitSound"]) > 2048:
raise ValueError("emitSound must be 2048 characters or less.")
return next_params