Merge branch 'fix/cafe24-ftp-temp-ext'

This commit is contained in:
2026-10-20 11:01:40 +09:00
4 changed files with 23 additions and 4 deletions
+10 -3
View File
@@ -85,10 +85,17 @@ def read_text_file(config: Cafe24FtpConfig, path: str) -> str:
def temp_names(path: str, tag: str) -> tuple[str, str]:
"""(임시 업로드 이름, 원본을 잠시 비킬 이름) — 같은 폴더, 원본 이름 + 표식."""
"""(임시 업로드 이름, 원본을 잠시 비킬 이름) — 같은 폴더, 원본 이름 + 표식.
⚠️ 원래 확장자를 **맨 끝에 그대로** 둔다. 카페24 디자인 FTP 는 허용된 확장자(.js·
.html·.css 등)만 받는다 — 예전 이름 `product-swiper.js.cf24tmp-…` 는 확장자가 바뀌어
STOR 가 `550 Operation not permitted` 로 거부됐다(실물). 그래서
`product-swiper_cf24tmp_<tag>.js` 모양으로 만든다(점·하이픈 대신 밑줄).
"""
folder, name = posixpath.split(path)
return (posixpath.join(folder, f"{name}.cf24tmp-{tag}"),
posixpath.join(folder, f"{name}.cf24old-{tag}"))
stem, ext = posixpath.splitext(name)
return (posixpath.join(folder, f"{stem}_cf24tmp_{tag}{ext}"),
posixpath.join(folder, f"{stem}_cf24old_{tag}{ext}"))
def write_text_file(
+1
View File
@@ -21,6 +21,7 @@
- 카페24 OAuth/API 클라이언트는 향후 주문관리와 공유하기 위해 **공통 계층 `app/integrations/cafe24/`** 에 둔다 — 라우터에서 `httpx`/`requests` 직접 호출 금지.
- 토큰은 Fernet 암호화 저장(`CAFE24_TOKEN_SECRET`), 로그/화면에 토큰·시크릿 절대 미출력.
- 쓰기 직전 항상 카페24 현재 HTML 을 다시 읽어 `BACKUP` revision 생성(로컬 값을 현재값으로 가정 금지).
- 디자인 FTP(스와이프·상품상세) 쓰기는 임시 파일 → 검증 → rename. **카페24 FTP 는 허용 확장자만 받으므로 임시 이름도 원래 확장자로 끝나야 함**(`x_cf24tmp_<tag>.js`, `design_ftp.temp_names`). `x.js.cf24tmp-…` 는 `550 Operation not permitted`.
- 예약은 DB 저장 + 별도 worker(`worker.py`, compose 서비스 `dbx-cafe24-worker`)가 처리 — 웹 프로세스에서 대기하지 않는다.
## 읽기 지연 ("마지막 쓰기가 권위")
+11
View File
@@ -478,10 +478,20 @@ class FakeFTP:
raise ftplib.error_perm("550 No such file")
callback(self.files[path])
# 카페24 디자인 FTP 는 허용 확장자만 받는다(실물: `x.js.cf24tmp-…` STOR → 550).
ALLOWED_EXT = (".js", ".html", ".htm", ".css", ".json", ".txt", ".xml",
".jpg", ".jpeg", ".gif", ".png", ".svg", ".webp")
@classmethod
def _check_ext(cls, path):
if not path.lower().endswith(cls.ALLOWED_EXT):
raise ftplib.error_perm(f"550 {path}: Operation not permitted")
def storbinary(self, cmd, fp):
path = cmd.split(" ", 1)[1]
data = fp.read()
FakeFTP.log.append(("STOR", path))
self._check_ext(path)
self.files[path] = data[: len(data) // 2] if FakeFTP.truncate_store else data
def rename(self, src, dst):
@@ -493,6 +503,7 @@ class FakeFTP:
raise ftplib.error_perm("502 RNFR not implemented")
if src not in self.files:
raise ftplib.error_perm("550 No such file")
self._check_ext(dst)
if dst in self.files and FakeFTP.rename_mode == "no_overwrite":
raise ftplib.error_perm("553 File exists")
self.files[dst] = self.files.pop(src)
+1 -1
View File
@@ -746,7 +746,7 @@ def test_design_ftp_read_and_write_roundtrip():
assert design_ftp.read_text_file(_FTP_CFG, _SWIPER) == "new content"
# 원본에 직접 STOR 하지 않는다 — 임시 파일에 올린 뒤 이름 바꾸기로 교체
stors = [e for e in ftp.log if e[0] == "STOR"]
assert stors and all(".cf24tmp-" in e[1] for e in stors), ftp.log
assert stors and all("_cf24tmp_" in e[1] and e[1].endswith(".js") for e in stors), ftp.log
assert any(e[0] == "RENAME" and e[2] == _SWIPER for e in ftp.log)
# 임시 파일이 남지 않는다
assert set(ftp.files) == {_SWIPER}