fix(cafe24): 대표이미지 적용 안 됨 + 옵션 썸네일 "없음" 오표시

- 대표이미지: NNEditor 업로드 경로를 PUT detail_image 에 넣던 방식은 카페24가
  반영하지 않았다. 문서의 전용 API POST /admin/products/{no}/images 에
  base64 data URI + image_upload_type=A 로 등록하고, 응답의 새 경로 4개로
  화면·스냅샷을 맞춘다(응답에 updated_date 가 없어 스냅샷 시각은 등록 시각).
- 옵션 썸네일: 카페24는 option_link_image 등을 "/web/product/big/…" 상대경로로
  준다. 그대로 src 에 넣어 우리 도메인에서 404 → "없음"으로 보였다. 옵션 GET 에
  image_base(쇼핑몰 주소)를 내려 붙여 그리고, 후보(버튼→연결→품목 이미지)가
  깨지면 다음 후보로 넘어간다. 카페24로 되보내는 hidden 값은 원본 그대로.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-28 00:33:17 +09:00
parent 81cd0ed0e9
commit e0dc818eab
7 changed files with 147 additions and 34 deletions
+42 -3
View File
@@ -346,9 +346,48 @@ def upload_image_bytes(client: Cafe24Client, data: bytes) -> str:
return paths[0] if paths else ""
def set_main_image(client: Cafe24Client, product_no: int, image_path: str) -> dict[str, Any]:
"""대표이미지 교체 — 목록/작은목록/축소 이미지는 카페24가 리사이징(A 타입)."""
return update_product(client, product_no, detail_image=image_path, image_upload_type="A")
def set_main_image(
client: Cafe24Client,
product_no: int,
data: bytes,
*,
content_type: str = "image/jpeg",
shop_no: int = 1,
) -> dict[str, str]:
"""대표이미지 교체 — POST /admin/products/{no}/images (상품 이미지 등록).
body `{"shop_no":1,"request":{"image_upload_type":"A","detail_image":"data:<mime>;base64,…"}}`
→ `{"image":{detail_image, list_image, tiny_image, small_image}}` (새 /web/product/… 경로).
A(대표이미지등록)면 카페24가 상세이미지를 리사이징해 목록/작은목록/축소에도 넣는다.
⚠️ `/admin/products/images`(상세설명 에디터용, /web/upload/NNEditor/…) 로 올린 경로를
`PUT /admin/products/{no}` 의 detail_image 에 넣는 방식은 대표이미지가 바뀌지 않았다
(실물 — "업로드했는데 적용 안 됨"). 대표이미지는 반드시 이 전용 API 로 등록한다.
"""
import base64 # noqa: WPS433
if not data:
return {}
no = int(product_no)
b64 = base64.b64encode(data).decode("ascii")
payload = {
"shop_no": int(shop_no),
"request": {
"image_upload_type": "A",
"detail_image": f"data:{content_type or 'image/jpeg'};base64,{b64}",
},
}
response = client.post(f"/admin/products/{no}/images", json=payload, product_no=no, timeout=UPLOAD_TIMEOUT)
image = response.get("image")
if isinstance(image, list): # 문서는 dict — 목록으로 올 때도 첫 건을 쓴다
image = image[0] if image else {}
if not isinstance(image, dict):
return {}
return {
key: str(image.get(key) or "")
for key in ("detail_image", "list_image", "tiny_image", "small_image")
if image.get(key)
}
# ════════════════════════════════════════════════════════════