Spaces:
Sleeping
Sleeping
File size: 1,319 Bytes
3493993 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | from __future__ import annotations
from typing import Any
from app.brand.errors import BrandValidationError
_PLATFORM_FIELDS: dict[str, frozenset[str]] = {
"facebook": frozenset({"caption_style", "hashtags", "cta"}),
"instagram": frozenset({"caption_style", "hashtags", "cta", "first_comment"}),
"tiktok": frozenset({"caption_style", "hashtags", "cta"}),
"x": frozenset({"caption_style", "hashtags", "cta"}),
"youtube": frozenset({"title_pattern", "description", "tags", "cta"}),
"linkedin": frozenset({"post_style", "hashtags", "cta"}),
"telegram": frozenset({"caption_style", "cta"}),
"whatsapp": frozenset({"caption_style", "cta"}),
}
def validate_platform_settings(provider: str, settings: dict[str, Any]) -> None:
unsupported = set(settings) - _PLATFORM_FIELDS.get(provider, frozenset())
if unsupported:
raise BrandValidationError(
f"Unsupported {provider} brand defaults: {', '.join(sorted(unsupported))}."
)
for key, value in settings.items():
if isinstance(value, str) and len(value) > 4000:
raise BrandValidationError(f"{provider}.{key} exceeds the supported length.")
if isinstance(value, list) and len(value) > 100:
raise BrandValidationError(f"{provider}.{key} contains too many values.")
|