fix(insta-render): _build_pages tolerates dict/list from NAS API
NAS GET /api/insta/slates/{id}는 cover_copy/body_copies/cta_copy를
이미 dict/list로 parse해서 반환 (main.py:193-198). 워커가 json.loads(dict)
시도하다 TypeError로 즉시 fail.
_coerce 헬퍼로 string / dict-list 둘 다 처리하도록 보완.
3 unit tests PASS (영향 없음).
Plan-B-Insta T15 fix.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -77,11 +77,24 @@ def _env() -> Environment:
|
||||
)
|
||||
|
||||
|
||||
def _coerce(value, default):
|
||||
"""NAS API는 cover_copy/body_copies/cta_copy를 dict/list로 반환하지만
|
||||
구버전 호환을 위해 JSON 문자열도 처리."""
|
||||
if value is None or value == "":
|
||||
return default
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except (ValueError, TypeError):
|
||||
return default
|
||||
return value
|
||||
|
||||
|
||||
def _build_pages(slate: dict) -> List[dict]:
|
||||
"""slate dict → 10 page specs."""
|
||||
cover = json.loads(slate["cover_copy"] or "{}")
|
||||
bodies = json.loads(slate["body_copies"] or "[]")
|
||||
cta = json.loads(slate["cta_copy"] or "{}")
|
||||
cover = _coerce(slate.get("cover_copy"), {})
|
||||
bodies = _coerce(slate.get("body_copies"), [])
|
||||
cta = _coerce(slate.get("cta_copy"), {})
|
||||
accent = cover.get("accent_color") or "#0F62FE"
|
||||
pages: List[dict] = []
|
||||
pages.append({
|
||||
|
||||
Reference in New Issue
Block a user