작품 삭제 기능: 수정 화면 DELETE — md·사진·페이지 제거, 되돌리기로 복구, 키트/마지막 작품 보호
This commit is contained in:
1 parent
bdbad3ec6d
commit
3d5a015400
3 files changed
+138
No files matched your search
@@ -91,6 +91,12 @@ bash scripts/studio.sh # http://localhost:8081
|
|||||||
- **고치기**: 목록 카드 오른쪽 `수정` → 제목·부제·본문·규격·소재·세탁·가격·날짜·네이버 링크·대표작/품절을 그대로 불러온다.
|
- **고치기**: 목록 카드 오른쪽 `수정` → 제목·부제·본문·규격·소재·세탁·가격·날짜·네이버 링크·대표작/품절을 그대로 불러온다.
|
||||||
사진은 순서 바꾸기(첫 장이 대표)·삭제·추가(촬영/앨범)가 되고, 저장하면 `assets/img/<slug>/` 를 다시 정리한다(쓰지 않는 사진은 지운다).
|
사진은 순서 바꾸기(첫 장이 대표)·삭제·추가(촬영/앨범)가 되고, 저장하면 `assets/img/<slug>/` 를 다시 정리한다(쓰지 않는 사진은 지운다).
|
||||||
`저장하고 사이트에 올리기` 또는 `저장만`. 저장 = md 재작성 → build → 커밋(`작품 수정: 제목`) → push.
|
`저장하고 사이트에 올리기` 또는 `저장만`. 저장 = md 재작성 → build → 커밋(`작품 수정: 제목`) → push.
|
||||||
|
- **삭제**: 수정 화면 맨 아래 `이 작품 삭제` → 확인 창 한 번이면 지운다. md + `assets/img/<slug>/` 를 함께 지우고
|
||||||
|
`작품 삭제: 제목` 커밋을 남긴 뒤 사이트에서도 내린다(목록·첫 페이지·상세 페이지에서 사라진다).
|
||||||
|
찍은 원본은 `data/photos/<slug>/` 에 남고, 이력에서 그 커밋을 되돌리면 md·사진·페이지가 그대로 살아난다.
|
||||||
|
실수 방지로 **첫 페이지 키트(`site.json` 의 `shop.kit_slug`)와 마지막 남은 한 점은 거부**한다.
|
||||||
|
커밋 안 된 다른 초안이 있으면 삭제는 하되 배포는 건너뛴다(목록의 `사이트에 올리기` 로 마저 올린다).
|
||||||
|
- `/m?slug=<슬러그>` 로 들어가면 그 작품 수정 화면이 바로 열린다.
|
||||||
- `사이트에 올리기` 는 **빌드까지 다시 한 뒤** 복사한다(되돌리기·수동 편집 뒤에도 안전).
|
- `사이트에 올리기` 는 **빌드까지 다시 한 뒤** 복사한다(되돌리기·수동 편집 뒤에도 안전).
|
||||||
- 저장 = `사진 축소(Pillow) → content/products/<slug>.md → build.py → git commit`(경로만 지정) → `git push`(Gitea). `사이트에 올리기` 를 누르면 `dist/` 를 웹 루트로 복사한다.
|
- 저장 = `사진 축소(Pillow) → content/products/<slug>.md → build.py → git commit`(경로만 지정) → `git push`(Gitea). `사이트에 올리기` 를 누르면 `dist/` 를 웹 루트로 복사한다.
|
||||||
- 사진은 `studio/_inbox/` 에 잠시 쌓였다가 발행 시 두 곳으로 나뉜다.
|
- 사진은 `studio/_inbox/` 에 잠시 쌓였다가 발행 시 두 곳으로 나뉜다.
|
||||||
|
|||||||
@@ -97,6 +97,8 @@
|
|||||||
.work-meta .price{color:var(--ink);font-size:13px}
|
.work-meta .price{color:var(--ink);font-size:13px}
|
||||||
.edit-btn{position:absolute;right:0;bottom:12px;border:1px solid var(--line);background:var(--white);
|
.edit-btn{position:absolute;right:0;bottom:12px;border:1px solid var(--line);background:var(--white);
|
||||||
color:var(--ink);font-size:13px;padding:8px 12px;cursor:pointer}
|
color:var(--ink);font-size:13px;padding:8px 12px;cursor:pointer}
|
||||||
|
.danger-zone{margin-top:28px;padding-top:18px;border-top:1px solid var(--line)}
|
||||||
|
.btn.danger{background:var(--clay);border-color:var(--clay);color:#fff}
|
||||||
.new-badge{position:absolute;right:0;top:10px;background:var(--sage);color:#fff;
|
.new-badge{position:absolute;right:0;top:10px;background:var(--sage);color:#fff;
|
||||||
font-size:10px;letter-spacing:.08em;padding:3px 6px}
|
font-size:10px;letter-spacing:.08em;padding:3px 6px}
|
||||||
</style>
|
</style>
|
||||||
@@ -278,6 +280,12 @@
|
|||||||
<div style="height:10px"></div>
|
<div style="height:10px"></div>
|
||||||
<button class="btn ghost" id="e-cancel">목록으로</button>
|
<button class="btn ghost" id="e-cancel">목록으로</button>
|
||||||
<div class="status" id="e-status"></div>
|
<div class="status" id="e-status"></div>
|
||||||
|
|
||||||
|
<div class="danger-zone">
|
||||||
|
<p class="label">DELETE</p>
|
||||||
|
<p class="note">지우면 목록과 상세 페이지에서 사라집니다. 찍은 원본 사진은 보관함에 남고, 이력에서 되돌리면 복구됩니다.</p>
|
||||||
|
<button class="btn danger" id="e-delete">이 작품 삭제</button>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -727,8 +735,41 @@ $('#e-save').onclick = () => saveEdit(true);
|
|||||||
$('#e-save-only').onclick = () => saveEdit(false);
|
$('#e-save-only').onclick = () => saveEdit(false);
|
||||||
$('#e-cancel').onclick = () => go('home');
|
$('#e-cancel').onclick = () => go('home');
|
||||||
|
|
||||||
|
/* ---------- 삭제 ---------- */
|
||||||
|
async function deleteWork(force){
|
||||||
|
if (!S.edit) return;
|
||||||
|
const slug = S.edit.slug;
|
||||||
|
const title = $('#e-title').value.trim() || slug;
|
||||||
|
const st = $('#e-status');
|
||||||
|
$('#e-delete').disabled = true;
|
||||||
|
st.innerHTML = '<span class="spin"></span> 지우는 중… (빌드 → 커밋 → 사이트 반영)';
|
||||||
|
try{
|
||||||
|
const d = await api('/api/delete', { slug, deploy:true, force: !!force });
|
||||||
|
const note = d.deployed
|
||||||
|
? '사이트에서도 내렸습니다.'
|
||||||
|
: (d.deploy_log || '저장소에서만 지웠습니다 — 사이트에는 아직 남아 있습니다.');
|
||||||
|
toast('삭제 완료');
|
||||||
|
go('home');
|
||||||
|
$('#deploy-status').innerHTML = `삭제했습니다 — <b>${d.title}</b> · 커밋 ${String(d.commit).slice(0,34)}<br>${note}`;
|
||||||
|
}catch(e){
|
||||||
|
st.innerHTML = `<span class="status err">${e.message}</span>`;
|
||||||
|
toast(e.message, 4000);
|
||||||
|
}finally{ $('#e-delete').disabled = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#e-delete').onclick = async () => {
|
||||||
|
if (!S.edit) return;
|
||||||
|
const title = $('#e-title').value.trim() || S.edit.slug;
|
||||||
|
const ok = confirm(`"${title}"을(를) 지울까요?\n\n목록과 상세 페이지에서 사라집니다.\n나중에 이력에서 되돌리면 그대로 살아납니다.`);
|
||||||
|
if (!ok) return;
|
||||||
|
await deleteWork(false);
|
||||||
|
};
|
||||||
|
|
||||||
/* ---------- 시작 ---------- */
|
/* ---------- 시작 ---------- */
|
||||||
go('home'); loadPresets();
|
go('home'); loadPresets();
|
||||||
|
// 목록의 링크나 알림에서 바로 열 수 있게: /m?slug=<슬러그> → 그 작품 고치기 화면
|
||||||
|
const deepSlug = new URLSearchParams(location.search).get('slug');
|
||||||
|
if (deepSlug) openEdit(deepSlug);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -440,6 +440,86 @@ def revert(sha: str, redeploy: bool) -> Dict[str, Any]:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def restore_paths(paths: List[str]) -> None:
|
||||||
|
"""git rm 으로 지운 파일을 커밋 전(HEAD) 상태 그대로 되살린다."""
|
||||||
|
git("reset", "-q", "HEAD", "--", *paths)
|
||||||
|
git("checkout", "HEAD", "--", *paths)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_product(slug: str, deploy_after: bool = False, force: bool = False) -> Dict[str, Any]:
|
||||||
|
"""작품 하나를 md·이미지 폴더와 함께 지운다.
|
||||||
|
|
||||||
|
- 빌드가 깨지면(예: 키트·대표작이 사라짐) 지운 파일을 HEAD 에서 되살리고 취소한다.
|
||||||
|
- 지운 사실은 `작품 삭제: 제목` 커밋으로 남는다 → 이력에서 revert 하면 그대로 복구된다.
|
||||||
|
"""
|
||||||
|
slug = str(slug or "").strip()
|
||||||
|
path = product_path(slug) # 슬러그 검증 + 파일 존재 확인
|
||||||
|
lines, _ = split_front(path.read_text(encoding="utf-8"))
|
||||||
|
_, data = parse_front(lines)
|
||||||
|
title = str(data.get("title") or slug)
|
||||||
|
|
||||||
|
if not [p for p in PRODUCTS.glob("*.md") if p.stem != slug]:
|
||||||
|
return {"ok": False, "error": "마지막 남은 작품은 지울 수 없습니다 — 첫 페이지가 비어 버립니다."}
|
||||||
|
|
||||||
|
try:
|
||||||
|
site = json.loads((ROOT / "content" / "site.json").read_text(encoding="utf-8"))
|
||||||
|
except (OSError, json.JSONDecodeError):
|
||||||
|
site = {}
|
||||||
|
kit_slug = str((site.get("shop") or {}).get("kit_slug") or "").strip()
|
||||||
|
if kit_slug and kit_slug == slug:
|
||||||
|
return {"ok": False, "error": "이 작품은 첫 페이지의 키트로 지정돼 있습니다. content/site.json 의 "
|
||||||
|
"shop.kit_slug 를 다른 작품으로 바꾼 뒤 지워 주세요."}
|
||||||
|
|
||||||
|
paths = [str(path.relative_to(ROOT))]
|
||||||
|
image_dir = ASSETS / "img" / slug
|
||||||
|
if image_dir.is_dir():
|
||||||
|
paths.append(str(image_dir.relative_to(ROOT)))
|
||||||
|
|
||||||
|
removed, rm_log = git("rm", "-r", "-f", "--quiet", "--", *paths)
|
||||||
|
if not removed:
|
||||||
|
return {"ok": False, "stage": "git_rm", "error": "작품 파일을 지우지 못했습니다", "log": rm_log}
|
||||||
|
|
||||||
|
built, build_log = build()
|
||||||
|
if not built:
|
||||||
|
restore_paths(paths)
|
||||||
|
build()
|
||||||
|
return {"ok": False, "stage": "build", "log": build_log[-800:],
|
||||||
|
"error": "빌드가 깨져 삭제를 취소하고 원래대로 되돌렸습니다"}
|
||||||
|
|
||||||
|
committed, commit_log = git("commit", "-m", f"작품 삭제: {title}", "--", *paths)
|
||||||
|
if not committed:
|
||||||
|
restore_paths(paths)
|
||||||
|
build()
|
||||||
|
return {"ok": False, "stage": "git", "error": "커밋에 실패해 삭제를 되돌렸습니다", "log": commit_log}
|
||||||
|
|
||||||
|
prune_empty_image_dirs()
|
||||||
|
summary = next((line for line in (build_log or "").splitlines() if line.startswith("검증")),
|
||||||
|
(build_log or "").splitlines()[0] if build_log else "")
|
||||||
|
result: Dict[str, Any] = {
|
||||||
|
"ok": True, "slug": slug, "title": title, "deployed": False, "pushed": False,
|
||||||
|
"message": f"삭제 · 커밋 완료 — {title}",
|
||||||
|
"commit": commit_log, "head": head_sha(),
|
||||||
|
"build_log": summary,
|
||||||
|
}
|
||||||
|
if os.environ.get("TEAMAT_PUSH", "").strip().lower() in ("1", "true", "yes"):
|
||||||
|
pushed, push_log = push()
|
||||||
|
result["pushed"] = pushed
|
||||||
|
result["push_log"] = push_log[-200:]
|
||||||
|
|
||||||
|
if deploy_after:
|
||||||
|
drafts = [d for d in reg.pending_drafts() if d != slug]
|
||||||
|
if drafts and not force:
|
||||||
|
result["drafts"] = drafts
|
||||||
|
result["deploy_log"] = ("커밋하지 않은 다른 초안이 있어 배포를 건너뛰었습니다: " + ", ".join(drafts)
|
||||||
|
+ " — 목록에서 [사이트에 올리기]로 마저 올려 주세요.")
|
||||||
|
else:
|
||||||
|
deployed, deploy_log = deploy()
|
||||||
|
result["deployed"] = deployed
|
||||||
|
result["deploy_log"] = deploy_log[-400:]
|
||||||
|
result["message"] += " · 사이트에 반영" if deployed else " (사이트 반영 실패)"
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def upload_image(name: str, data: bytes, slug: str = "") -> Dict[str, Any]:
|
def upload_image(name: str, data: bytes, slug: str = "") -> Dict[str, Any]:
|
||||||
"""이미지는 assets/img/<작품슬러그>/ 에 넣는다. 작품마다 폴더 하나."""
|
"""이미지는 assets/img/<작품슬러그>/ 에 넣는다. 작품마다 폴더 하나."""
|
||||||
if not data:
|
if not data:
|
||||||
@@ -867,6 +947,17 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
except (RuntimeError, FileNotFoundError) as error:
|
except (RuntimeError, FileNotFoundError) as error:
|
||||||
self.send_json({"ok": False, "error": str(error)}, 500)
|
self.send_json({"ok": False, "error": str(error)}, 500)
|
||||||
return
|
return
|
||||||
|
if path == "/api/delete":
|
||||||
|
payload = self.read_json()
|
||||||
|
try:
|
||||||
|
self.send_json(delete_product(str(payload.get("slug") or ""),
|
||||||
|
bool(payload.get("deploy")),
|
||||||
|
bool(payload.get("force"))))
|
||||||
|
except FileNotFoundError as error:
|
||||||
|
self.send_json({"ok": False, "error": str(error)}, 404)
|
||||||
|
except ValueError as error:
|
||||||
|
self.send_json({"ok": False, "error": str(error)}, 400)
|
||||||
|
return
|
||||||
if path == "/api/product":
|
if path == "/api/product":
|
||||||
try:
|
try:
|
||||||
self.send_json(save_product(self.read_json()))
|
self.send_json(save_product(self.read_json()))
|
||||||
|
|||||||
Reference in new issue
Block a user