Spaces:
Running
Running
Fix truncated input resolver and restore missing helpers (#1)
Browse files- Fix truncated input resolver and restore missing helpers (c50a399459598f0e1dee6e8e234a97890014edff)
app/services/input_resolver.py
CHANGED
|
@@ -464,4 +464,59 @@ class InputResolver:
|
|
| 464 |
if isinstance(value, str):
|
| 465 |
stripped = value.strip()
|
| 466 |
if stripped.startswith(("http://", "https://")):
|
| 467 |
-
return [{"url"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
if isinstance(value, str):
|
| 465 |
stripped = value.strip()
|
| 466 |
if stripped.startswith(("http://", "https://")):
|
| 467 |
+
return [{"url": stripped}]
|
| 468 |
+
return []
|
| 469 |
+
if any(key in value for key in ("url", "base64", "temp_path", "path", "asset_id")):
|
| 470 |
+
return [value]
|
| 471 |
+
if "data" in value and (
|
| 472 |
+
binary or any(key in value for key in ("fileName", "filename", "mimeType", "mime_type"))
|
| 473 |
+
):
|
| 474 |
+
return [value]
|
| 475 |
+
result: list[dict[str, Any]] = []
|
| 476 |
+
for key, item in value.items():
|
| 477 |
+
if key in self.INPUT_KEYS:
|
| 478 |
+
result.extend(self._collect_descriptors(item, binary=(key == "binary")))
|
| 479 |
+
elif binary and isinstance(item, (dict, list)):
|
| 480 |
+
result.extend(self._collect_descriptors(item, binary=True))
|
| 481 |
+
return result
|
| 482 |
+
|
| 483 |
+
def _params_from_payload(self, payload: dict[str, Any]) -> dict[str, Any]:
|
| 484 |
+
"""Keep operation parameters while excluding fields consumed as media inputs."""
|
| 485 |
+
if not isinstance(payload, dict):
|
| 486 |
+
return {}
|
| 487 |
+
return {key: value for key, value in payload.items() if key not in self.INPUT_KEYS}
|
| 488 |
+
|
| 489 |
+
@staticmethod
|
| 490 |
+
def _as_list(value: Any) -> list[Any]:
|
| 491 |
+
return value if isinstance(value, list) else [value]
|
| 492 |
+
|
| 493 |
+
@staticmethod
|
| 494 |
+
def _parse_field(value: Any) -> Any:
|
| 495 |
+
if not isinstance(value, str):
|
| 496 |
+
return value
|
| 497 |
+
stripped = value.strip()
|
| 498 |
+
if not stripped:
|
| 499 |
+
return stripped
|
| 500 |
+
try:
|
| 501 |
+
return json.loads(stripped)
|
| 502 |
+
except json.JSONDecodeError:
|
| 503 |
+
return value
|
| 504 |
+
|
| 505 |
+
@staticmethod
|
| 506 |
+
def _int(value: Any) -> int | None:
|
| 507 |
+
if value is None or isinstance(value, bool):
|
| 508 |
+
return None
|
| 509 |
+
try:
|
| 510 |
+
return int(value)
|
| 511 |
+
except (TypeError, ValueError, OverflowError):
|
| 512 |
+
return None
|
| 513 |
+
|
| 514 |
+
@staticmethod
|
| 515 |
+
def _original_name(path: Path) -> str:
|
| 516 |
+
name = path.name
|
| 517 |
+
# Downloader prefixes names with a random identifier for collision safety.
|
| 518 |
+
if "_" in name:
|
| 519 |
+
prefix, remainder = name.split("_", 1)
|
| 520 |
+
if len(prefix) == 32 and all(ch in "0123456789abcdef" for ch in prefix.lower()):
|
| 521 |
+
return remainder
|
| 522 |
+
return name
|