mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 06:32:12 -03:00
feat: parse aggregate commercial use values, see #708
Add support for parsing comma-separated and JSON-style commercial use permission values in both Python backend and JavaScript frontend. Implement helper functions to split aggregated values into individual permissions while preserving original values when no aggregation is detected. Added comprehensive test coverage for the new parsing functionality to ensure correct handling of various input formats including strings, arrays, and iterable objects with aggregated commercial use values.
This commit is contained in:
@@ -20,11 +20,25 @@ _COMMERCIAL_SHIFT = 1
|
||||
def _normalize_commercial_values(value: Any) -> Sequence[str]:
|
||||
"""Return a normalized list of commercial permissions preserving source values."""
|
||||
|
||||
def _split_aggregate(value_str: str) -> list[str]:
|
||||
stripped = value_str.strip()
|
||||
looks_aggregate = "," in stripped or (stripped.startswith("{") and stripped.endswith("}"))
|
||||
if not looks_aggregate:
|
||||
return [value_str]
|
||||
|
||||
trimmed = stripped
|
||||
if trimmed.startswith("{") and trimmed.endswith("}"):
|
||||
trimmed = trimmed[1:-1]
|
||||
|
||||
parts = [part.strip() for part in trimmed.split(",")]
|
||||
result = [part for part in parts if part]
|
||||
return result or [value_str]
|
||||
|
||||
if value is None:
|
||||
return list(_DEFAULT_ALLOW_COMMERCIAL_USE)
|
||||
|
||||
if isinstance(value, str):
|
||||
return [value]
|
||||
return _split_aggregate(value)
|
||||
|
||||
if isinstance(value, Iterable):
|
||||
result = []
|
||||
@@ -32,7 +46,7 @@ def _normalize_commercial_values(value: Any) -> Sequence[str]:
|
||||
if item is None:
|
||||
continue
|
||||
if isinstance(item, str):
|
||||
result.append(item)
|
||||
result.extend(_split_aggregate(item))
|
||||
continue
|
||||
result.append(str(item))
|
||||
if result:
|
||||
|
||||
Reference in New Issue
Block a user