677 lines
33 KiB
HTML
677 lines
33 KiB
HTML
<!doctype html>
|
||
<html lang="ko">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||
<meta name="theme-color" content="#F6F2EA">
|
||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||
<title>한땀 작업실 — 상품 등록</title>
|
||
<link rel="manifest" href="manifest.json">
|
||
<link rel="apple-touch-icon" href="../assets/img/process/stitch.jpg">
|
||
<style>
|
||
:root{
|
||
--paper:#F6F2EA; --ink:#26241F; --muted:#6B6357; --sage:#6C7A63;
|
||
--clay:#A2705A; --line:#DCD3C4; --white:#FFFDF8;
|
||
--serif:"Noto Serif KR","Apple SD Gothic Neo",serif;
|
||
--sans:-apple-system,BlinkMacSystemFont,"Apple SD Gothic Neo","Noto Sans KR",system-ui,sans-serif;
|
||
--safe-b:env(safe-area-inset-bottom,0px);
|
||
}
|
||
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
|
||
html,body{margin:0;background:var(--paper);color:var(--ink);font-family:var(--sans);
|
||
font-size:16px;line-height:1.65;overscroll-behavior-y:contain}
|
||
body{padding-bottom:calc(96px + var(--safe-b))}
|
||
header{position:sticky;top:0;z-index:20;background:rgba(246,242,234,.94);
|
||
backdrop-filter:blur(8px);border-bottom:1px solid var(--line)}
|
||
.head-in{display:flex;align-items:center;gap:10px;padding:12px 18px}
|
||
.brand{font-family:var(--serif);font-size:17px;letter-spacing:.02em}
|
||
.brand small{font-family:var(--sans);font-size:11px;letter-spacing:.18em;color:var(--muted);margin-left:8px}
|
||
.steps{margin-left:auto;font-size:12px;color:var(--muted);letter-spacing:.08em}
|
||
main{padding:18px}
|
||
section[hidden]{display:none}
|
||
h1{font-family:var(--serif);font-weight:400;font-size:24px;margin:6px 0 14px}
|
||
h2{font-family:var(--serif);font-weight:400;font-size:19px;margin:0 0 6px}
|
||
.label{font-size:11px;letter-spacing:.18em;color:var(--muted);text-transform:uppercase;margin:0 0 10px}
|
||
.note{color:var(--muted);font-size:14px;margin:0 0 18px}
|
||
.btn{display:flex;align-items:center;justify-content:center;gap:8px;width:100%;
|
||
padding:16px;border:1px solid var(--ink);background:var(--ink);color:var(--paper);
|
||
font-family:var(--sans);font-size:16px;border-radius:0;cursor:pointer}
|
||
.btn:active{opacity:.82}
|
||
.btn.ghost{background:transparent;color:var(--ink);border-color:var(--line)}
|
||
.btn.sage{background:var(--sage);border-color:var(--sage)}
|
||
.btn:disabled{opacity:.45}
|
||
.btn-sm{padding:10px 14px;font-size:14px;width:auto}
|
||
.stack{display:grid;gap:10px}
|
||
.row2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
||
.card{background:var(--white);border:1px solid var(--line);padding:14px;margin-bottom:10px}
|
||
.thumbs{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:14px}
|
||
.thumb{position:relative;background:var(--line);aspect-ratio:4/5;overflow:hidden}
|
||
.thumb img{width:100%;height:100%;object-fit:cover;display:block}
|
||
.thumb .badge{position:absolute;left:0;top:0;background:var(--ink);color:var(--paper);
|
||
font-size:11px;letter-spacing:.1em;padding:3px 7px}
|
||
.thumb .tools{position:absolute;right:0;bottom:0;display:flex;gap:4px;padding:6px}
|
||
.thumb .tools button{width:34px;height:34px;border:none;background:rgba(38,36,31,.82);
|
||
color:#fff;font-size:15px;line-height:1;cursor:pointer}
|
||
.thumb .tools button.del{background:rgba(162,112,90,.92)}
|
||
label.field{display:block;margin-bottom:14px}
|
||
label.field span{display:block;font-size:12px;letter-spacing:.1em;color:var(--muted);margin-bottom:6px}
|
||
input[type=text],input[type=number],input[type=url],input[type=date],textarea{
|
||
width:100%;padding:13px 12px;border:1px solid var(--line);background:var(--white);
|
||
font-family:var(--sans);font-size:16px;color:var(--ink);border-radius:0}
|
||
textarea{min-height:150px;line-height:1.7;resize:vertical}
|
||
.chips{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 10px}
|
||
.chip{padding:9px 12px;border:1px solid var(--line);background:var(--white);
|
||
font-size:13px;cursor:pointer;color:var(--muted)}
|
||
.chip[aria-pressed=true]{border-color:var(--sage);background:#EEF0E9;color:var(--ink)}
|
||
.bar{display:none;position:fixed;left:0;right:0;bottom:0;z-index:30;background:rgba(246,242,234,.97);
|
||
border-top:1px solid var(--line);padding:12px 18px calc(12px + var(--safe-b));
|
||
display:grid;grid-template-columns:auto 1fr;gap:10px;align-items:center}
|
||
.bar .hint{font-size:12px;color:var(--muted);line-height:1.4}
|
||
.facts{white-space:pre-wrap;font-size:13px;color:var(--muted);background:#EFEBE1;
|
||
border-left:2px solid var(--sage);padding:12px;margin:0 0 16px}
|
||
.voice{background:var(--white);border:1px solid var(--line);color:var(--ink);
|
||
padding:10px 12px;font-size:14px;cursor:pointer}
|
||
.voice.rec{background:var(--clay);color:#fff;border-color:var(--clay)}
|
||
.list-item{display:flex;justify-content:space-between;align-items:baseline;gap:10px;
|
||
padding:13px 2px;border-bottom:1px solid var(--line);text-decoration:none;color:var(--ink)}
|
||
.list-item small{color:var(--muted)}
|
||
.status{font-size:13px;color:var(--muted);margin-top:10px;min-height:20px}
|
||
.status.err{color:#9B3B2A}
|
||
.toast{position:fixed;left:50%;bottom:calc(110px + var(--safe-b));transform:translateX(-50%);
|
||
background:var(--ink);color:var(--paper);padding:11px 16px;font-size:14px;z-index:50;
|
||
opacity:0;pointer-events:none;transition:opacity .2s;max-width:88vw;text-align:center}
|
||
.toast.on{opacity:1}
|
||
.spin{display:inline-block;width:14px;height:14px;border:2px solid var(--line);
|
||
border-top-color:var(--ink);border-radius:50%;animation:sp .8s linear infinite;vertical-align:-2px}
|
||
@keyframes sp{to{transform:rotate(360deg)}}
|
||
.summary{font-size:14px;color:var(--muted);margin-bottom:14px}
|
||
.summary b{color:var(--ink);font-weight:500}
|
||
a.live{color:var(--sage)}
|
||
.work-card{display:block;position:relative;padding:10px 0;border-bottom:1px solid var(--line)}
|
||
.work-open{display:grid;grid-template-columns:88px 1fr;gap:12px;align-items:center;
|
||
text-decoration:none;color:var(--ink);padding-right:64px}
|
||
.work-open img{width:88px;aspect-ratio:4/5;object-fit:cover;background:var(--line);display:block}
|
||
.work-meta{display:grid;gap:3px;min-width:0}
|
||
.work-meta strong{font-weight:500;font-size:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||
.work-meta span{font-size:12px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||
.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);
|
||
color:var(--ink);font-size:13px;padding:8px 12px;cursor:pointer}
|
||
.new-badge{position:absolute;right:0;top:10px;background:var(--sage);color:#fff;
|
||
font-size:10px;letter-spacing:.08em;padding:3px 6px}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<header>
|
||
<div class="head-in">
|
||
<span class="brand">한땀<small>WORKSPACE</small></span>
|
||
<span class="steps" id="steps">등록</span>
|
||
</div>
|
||
</header>
|
||
|
||
<main>
|
||
<!-- ① 홈: 작품 목록 -->
|
||
<section id="s-home">
|
||
<p class="label">WORKS</p>
|
||
<h1>작품 목록</h1>
|
||
<p class="note" id="home-note">불러오는 중…</p>
|
||
<button class="btn" id="start">신규 상품 등록</button>
|
||
<div style="height:10px"></div>
|
||
<button class="btn ghost" id="deploy-all">사이트에 올리기</button>
|
||
<div class="status" id="deploy-status"></div>
|
||
<div id="home-list" style="margin-top:16px">
|
||
<span class="status"><span class="spin"></span> 불러오는 중</span>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ② 사진 -->
|
||
<section id="s-photos" hidden>
|
||
<p class="label">STEP 1 · 사진</p>
|
||
<h1>사진을 찍으세요</h1>
|
||
<p class="note">여러 장이면 계속 찍으세요. 첫 장이 대표 사진이 됩니다.</p>
|
||
<div class="row2">
|
||
<button class="btn" id="shoot">사진 찍기</button>
|
||
<button class="btn ghost" id="pick">앨범에서</button>
|
||
</div>
|
||
<input type="file" id="cam" accept="image/*" capture="environment" hidden>
|
||
<input type="file" id="album" accept="image/*" multiple hidden>
|
||
<div class="thumbs" id="thumbs" style="margin-top:16px"></div>
|
||
<div class="status" id="up-status"></div>
|
||
</section>
|
||
|
||
<!-- ③ 내용 -->
|
||
<section id="s-write" hidden>
|
||
<p class="label">STEP 2 · 내용</p>
|
||
<h1>내용 작성</h1>
|
||
<p class="note">사진을 읽어 초안을 씁니다. 말로 덧붙이면 그 내용이 반영됩니다.</p>
|
||
<label class="field">
|
||
<span>메모 (선택) — 말로 넣어도 됩니다</span>
|
||
<textarea id="note" style="min-height:84px" placeholder="예: 와인색 코튼린넨, 네 장, 사시코 실 포함"></textarea>
|
||
</label>
|
||
<div class="chips"><button class="voice" id="voice">🎙 말로 적기</button></div>
|
||
<button class="btn sage" id="cap">내용 작성</button>
|
||
<div class="status" id="cap-status"></div>
|
||
<div id="cap-out" hidden style="margin-top:18px">
|
||
<p class="label">사진에서 읽은 것</p>
|
||
<pre class="facts" id="facts"></pre>
|
||
<label class="field"><span>제목</span><input type="text" id="f-title"></label>
|
||
<label class="field"><span>부제</span><input type="text" id="f-subtitle"></label>
|
||
<label class="field"><span>본문</span><textarea id="f-body" style="min-height:230px"></textarea></label>
|
||
<label class="field"><span>사진 설명(alt)</span><input type="text" id="f-alt"></label>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ④ 항목 -->
|
||
<section id="s-specs" hidden>
|
||
<p class="label">STEP 3 · 항목</p>
|
||
<h1>규격과 가격</h1>
|
||
<p class="note">표준값을 누르면 채워집니다. 다르면 직접 고쳐 쓰세요.</p>
|
||
|
||
<label class="field"><span>규격</span><input type="text" id="f-size"></label>
|
||
<div class="chips" data-for="f-size"></div>
|
||
|
||
<label class="field"><span>소재</span><input type="text" id="f-material"></label>
|
||
<div class="chips" data-for="f-material"></div>
|
||
|
||
<label class="field"><span>세탁</span><input type="text" id="f-care"></label>
|
||
<div class="chips" data-for="f-care"></div>
|
||
|
||
<div class="row2">
|
||
<label class="field"><span>가격(원) · 비우면 "문의"</span><input type="number" id="f-price" inputmode="numeric"></label>
|
||
<label class="field"><span>날짜</span><input type="date" id="f-date"></label>
|
||
</div>
|
||
<label class="field"><span>가격 옵션 안내 (선택)</span><input type="text" id="f-pricenote" placeholder="예: 네 장 세트 50,000원"></label>
|
||
<label class="field"><span>네이버 링크 (선택)</span><input type="url" id="f-naver" placeholder="https://smartstore.naver.com/..."></label>
|
||
<label class="field" style="display:flex;gap:10px;align-items:center">
|
||
<input type="checkbox" id="f-featured" style="width:20px;height:20px">
|
||
<span style="margin:0">첫 페이지 대표작으로</span>
|
||
</label>
|
||
<label class="field" style="display:flex;gap:10px;align-items:center">
|
||
<input type="checkbox" id="f-soldout" style="width:20px;height:20px">
|
||
<span style="margin:0">품절 표시</span>
|
||
</label>
|
||
</section>
|
||
|
||
<!-- ⑤ 확인 -->
|
||
<section id="s-done" hidden>
|
||
<p class="label">STEP 4 · 저장</p>
|
||
<h1>이대로 만들까요?</h1>
|
||
<div class="card" id="summary"></div>
|
||
<button class="btn" id="pub-deploy">저장하고 사이트에 올리기</button>
|
||
<div style="height:10px"></div>
|
||
<button class="btn ghost" id="pub-only">저장만 (배포는 나중에)</button>
|
||
<label class="field" style="display:flex;gap:10px;align-items:center;margin-top:16px">
|
||
<input type="checkbox" id="force" style="width:20px;height:20px">
|
||
<span style="margin:0">다른 초안도 함께 올리기</span>
|
||
</label>
|
||
<div class="status" id="pub-status"></div>
|
||
<div class="stack" id="after-publish" hidden style="margin-top:16px">
|
||
<button class="btn sage" id="to-list">목록으로 돌아가기</button>
|
||
<a class="btn ghost" id="open-preview" href="#" target="_blank" rel="noopener">이 작품 페이지 열기</a>
|
||
<a class="btn ghost" id="open-live" href="#" target="_blank" rel="noopener" hidden>사이트에서 보기</a>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ⑥ 고치기 -->
|
||
<section id="s-edit" hidden>
|
||
<p class="label">EDIT</p>
|
||
<h1 id="edit-head">작품 고치기</h1>
|
||
<p class="note" id="edit-slug"></p>
|
||
|
||
<p class="label">사진</p>
|
||
<div class="thumbs" id="edit-thumbs"></div>
|
||
<div class="row2">
|
||
<button class="btn ghost" id="edit-shoot">사진 찍어 추가</button>
|
||
<a class="btn ghost" id="edit-open" href="#" target="_blank" rel="noopener">페이지 열기</a>
|
||
</div>
|
||
<button class="btn ghost btn-sm" id="edit-album-btn" style="width:100%;margin-top:8px">앨범에서 추가</button>
|
||
<input type="file" id="edit-cam" accept="image/*" capture="environment" hidden>
|
||
<input type="file" id="edit-album" accept="image/*" multiple hidden>
|
||
<div class="status" id="edit-up"></div>
|
||
|
||
<div style="margin-top:18px">
|
||
<label class="field"><span>제목</span><input type="text" id="e-title"></label>
|
||
<label class="field"><span>부제</span><input type="text" id="e-subtitle"></label>
|
||
<label class="field"><span>본문</span><textarea id="e-body" style="min-height:220px"></textarea></label>
|
||
<label class="field"><span>사진 설명(alt)</span><input type="text" id="e-alt"></label>
|
||
|
||
<label class="field"><span>규격</span><input type="text" id="e-size"></label>
|
||
<div class="chips" data-for="e-size"></div>
|
||
<label class="field"><span>소재</span><input type="text" id="e-material"></label>
|
||
<div class="chips" data-for="e-material"></div>
|
||
<label class="field"><span>세탁</span><input type="text" id="e-care"></label>
|
||
<div class="chips" data-for="e-care"></div>
|
||
|
||
<div class="row2">
|
||
<label class="field"><span>가격(원)</span><input type="number" id="e-price" inputmode="numeric"></label>
|
||
<label class="field"><span>날짜</span><input type="date" id="e-date"></label>
|
||
</div>
|
||
<label class="field"><span>가격 옵션 안내</span><input type="text" id="e-pricenote"></label>
|
||
<label class="field"><span>네이버 링크</span><input type="url" id="e-naver"></label>
|
||
<label class="field" style="display:flex;gap:10px;align-items:center">
|
||
<input type="checkbox" id="e-featured" style="width:20px;height:20px"><span style="margin:0">첫 페이지 대표작으로</span>
|
||
</label>
|
||
<label class="field" style="display:flex;gap:10px;align-items:center">
|
||
<input type="checkbox" id="e-soldout" style="width:20px;height:20px"><span style="margin:0">품절 표시</span>
|
||
</label>
|
||
</div>
|
||
|
||
<button class="btn sage" id="e-save">저장하고 사이트에 올리기</button>
|
||
<div style="height:10px"></div>
|
||
<button class="btn ghost" id="e-save-only">저장만</button>
|
||
<div style="height:10px"></div>
|
||
<button class="btn ghost" id="e-cancel">목록으로</button>
|
||
<div class="status" id="e-status"></div>
|
||
</section>
|
||
</main>
|
||
|
||
<div class="bar" id="bar">
|
||
<button class="btn ghost btn-sm" id="back">이전</button>
|
||
<button class="btn" id="next">다음</button>
|
||
</div>
|
||
<div class="toast" id="toast"></div>
|
||
|
||
<script>
|
||
const S = { step:'home', photos:[], facts:'', draft:{}, busy:false, presets:null };
|
||
|
||
const $ = s => document.querySelector(s);
|
||
const toast = (m, ms=2200) => { const t=$('#toast'); t.textContent=m; t.classList.add('on');
|
||
clearTimeout(t._h); t._h=setTimeout(()=>t.classList.remove('on'), ms); };
|
||
|
||
async function api(path, body){
|
||
const res = await fetch(path, body===undefined ? {} : {
|
||
method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify(body)
|
||
});
|
||
if (res.status === 401){ location.href = '/?t=' ; throw new Error('인증이 풀렸습니다'); }
|
||
const data = await res.json().catch(()=>({ok:false,error:'응답을 읽지 못했습니다'}));
|
||
if (!res.ok || data.ok === false) throw new Error(data.error || ('오류 '+res.status));
|
||
return data;
|
||
}
|
||
|
||
/* ---------- 단계 이동 ---------- */
|
||
const STEPS = {
|
||
home:{el:'#s-home', n:'', prev:null, next:null},
|
||
photos:{el:'#s-photos', n:'1/4 사진', prev:'home', next:'write'},
|
||
write:{el:'#s-write', n:'2/4 내용', prev:'photos', next:'specs'},
|
||
specs:{el:'#s-specs', n:'3/4 항목', prev:'write', next:'done'},
|
||
done:{el:'#s-done', n:'4/4 저장', prev:'specs', next:null},
|
||
edit:{el:'#s-edit', n:'고치기', prev:null, next:null},
|
||
};
|
||
function go(step){
|
||
S.step = step;
|
||
Object.values(STEPS).forEach(v => $(v.el).hidden = true);
|
||
$(STEPS[step].el).hidden = false;
|
||
$('#steps').textContent = STEPS[step].n;
|
||
const cfg = STEPS[step];
|
||
$('#bar').style.display = (step==='home' || step==='edit') ? 'none' : 'grid';
|
||
$('#back').style.visibility = cfg.prev ? 'visible' : 'hidden';
|
||
const next = $('#next');
|
||
next.textContent = step==='specs' ? '확인' : '다음';
|
||
next.style.display = cfg.next ? '' : 'none';
|
||
if (step==='done') renderSummary();
|
||
if (step==='home') loadHome();
|
||
window.scrollTo({top:0});
|
||
}
|
||
$('#back').onclick = () => { const p = STEPS[S.step].prev; if (p) go(p); };
|
||
$('#next').onclick = () => {
|
||
if (S.step==='photos' && !S.photos.length){ toast('사진을 한 장 이상 올려 주세요'); return; }
|
||
if (S.step==='write'){
|
||
if (!$('#f-title').value.trim() || !$('#f-body').value.trim()){
|
||
toast('먼저 "내용 작성"을 눌러 초안을 만들어 주세요'); return; }
|
||
}
|
||
go(STEPS[S.step].next);
|
||
};
|
||
|
||
/* ---------- 홈: 작품 목록 ---------- */
|
||
async function loadHome(){
|
||
try{
|
||
const d = await api('/api/state');
|
||
S.site = d.site_url || '';
|
||
const rows = (d.products || []).slice().sort((a,b) =>
|
||
String(b.date||'').localeCompare(String(a.date||'')) || (b.mtime||0)-(a.mtime||0));
|
||
$('#home-note').textContent = rows.length
|
||
? rows.length + '점 · 최근에 만든 순서입니다. 눌러서 확인하세요.'
|
||
: '아직 등록한 작품이 없습니다.';
|
||
$('#home-list').innerHTML = rows.map(p => `
|
||
<div class="work-card">
|
||
<a class="work-open" href="/p/${p.slug}.html" target="_blank" rel="noopener">
|
||
${p.image ? `<img src="/${p.image}" alt="" loading="lazy">` : '<span></span>'}
|
||
<div class="work-meta">
|
||
<strong>${p.title}</strong>
|
||
<span>${p.subtitle || ''}</span>
|
||
<span class="price">${p.price ? Number(p.price).toLocaleString('ko-KR') + '원' : '가격 문의'}${p.sold_out ? ' · 판매 완료' : ''}</span>
|
||
</div>
|
||
</a>
|
||
<button class="edit-btn" data-slug="${p.slug}">수정</button>
|
||
${S.lastSlug === p.slug ? '<span class="new-badge">방금 등록</span>'
|
||
: (p.live === false ? '<span class="new-badge" style="background:var(--clay)">미발행</span>' : '')}
|
||
</div>`).join('') || '<p class="note">아직 없습니다.</p>';
|
||
|
||
document.querySelectorAll('.edit-btn').forEach(b => b.onclick = () => openEdit(b.dataset.slug));
|
||
|
||
const pending = rows.filter(p => p.live === false).length;
|
||
const button = $('#deploy-all');
|
||
button.disabled = pending === 0;
|
||
button.style.display = pending ? 'flex' : 'none';
|
||
button.textContent = pending ? `사이트에 올리기 (미발행 ${pending}점)` : '사이트 최신 상태';
|
||
}catch(e){
|
||
$('#home-note').textContent = '';
|
||
$('#home-list').innerHTML = `<span class="status err">${e.message}</span>`;
|
||
}
|
||
}
|
||
|
||
$('#start').onclick = () => {
|
||
S.photos = []; S.facts=''; S.draft={}; S.lastSlug = null;
|
||
$('#after-publish').hidden = true; $('#pub-status').textContent = '';
|
||
['#f-title','#f-subtitle','#f-body','#f-alt','#f-size','#f-material','#f-care','#f-price',
|
||
'#f-pricenote','#f-naver','#note'].forEach(s=>{ if($(s)) $(s).value=''; });
|
||
$('#f-date').value = new Date().toISOString().slice(0,10);
|
||
$('#f-featured').checked = false; $('#f-soldout').checked = false;
|
||
$('#cap-out').hidden = true; $('#cap-status').textContent = '';
|
||
renderPhotos(); go('photos');
|
||
};
|
||
|
||
/* ---------- 사진 ---------- */
|
||
$('#shoot').onclick = () => $('#cam').click();
|
||
$('#pick').onclick = () => $('#album').click();
|
||
$('#cam').onchange = e => uploadFiles(e.target.files, true);
|
||
$('#album').onchange = e => uploadFiles(e.target.files, false);
|
||
|
||
async function uploadFiles(files, single){
|
||
const list = Array.from(files || []);
|
||
if (!list.length) return;
|
||
for (let i=0;i<list.length;i++){
|
||
$('#up-status').innerHTML = `<span class="spin"></span> 사진 올리는 중 ${i+1}/${list.length}`;
|
||
try{
|
||
const res = await fetch('/api/photo?name=' + encodeURIComponent(list[i].name || 'photo.jpg'),
|
||
{method:'POST', headers:{'Content-Type':'application/octet-stream'}, body:list[i]});
|
||
const d = await res.json();
|
||
if (!res.ok || d.ok===false) throw new Error(d.error || '업로드 실패');
|
||
S.photos.push({uid:d.uid, name:list[i].name});
|
||
}catch(e){ $('#up-status').innerHTML = `<span class="status err">${e.message}</span>`; return; }
|
||
}
|
||
$('#up-status').textContent = '';
|
||
$('#cam').value=''; $('#album').value='';
|
||
renderPhotos();
|
||
}
|
||
|
||
function renderPhotos(){
|
||
const box = $('#thumbs');
|
||
if (!S.photos.length){ box.innerHTML = `<p class="note" style="grid-column:1/-1">아직 사진이 없습니다.</p>`; return; }
|
||
box.innerHTML = S.photos.map((p,i)=>`
|
||
<div class="thumb">
|
||
<img src="/media-inbox/${p.uid}.jpg" alt="">
|
||
${i===0?'<span class="badge">대표</span>':''}
|
||
<div class="tools">
|
||
${i>0?`<button data-mv="${i}:-1" aria-label="앞으로">←</button>`:''}
|
||
${i<S.photos.length-1?`<button data-mv="${i}:1" aria-label="뒤로">→</button>`:''}
|
||
<button class="del" data-del="${i}" aria-label="삭제">×</button>
|
||
</div>
|
||
</div>`).join('');
|
||
box.querySelectorAll('[data-del]').forEach(b=>b.onclick=()=>{
|
||
S.photos.splice(+b.dataset.del,1); renderPhotos();
|
||
});
|
||
box.querySelectorAll('[data-mv]').forEach(b=>b.onclick=()=>{
|
||
const [i,d] = b.dataset.mv.split(':').map(Number);
|
||
const j = i+d; if (j<0||j>=S.photos.length) return;
|
||
[S.photos[i],S.photos[j]] = [S.photos[j],S.photos[i]]; renderPhotos();
|
||
});
|
||
}
|
||
|
||
/* ---------- 내용 작성 ---------- */
|
||
$('#cap').onclick = async () => {
|
||
if (!S.photos.length){ toast('사진을 먼저 올려 주세요'); return; }
|
||
$('#cap').disabled = true;
|
||
$('#cap-status').innerHTML = '<span class="spin"></span> 사진을 읽고 문장을 쓰는 중… (10~30초)';
|
||
try{
|
||
const d = await api('/api/caption', {
|
||
photos: S.photos.map(p=>p.uid),
|
||
note: $('#note').value.trim(),
|
||
known: { size:$('#f-size').value.trim(), material:$('#f-material').value.trim(),
|
||
care:$('#f-care').value.trim(), price:$('#f-price').value }
|
||
});
|
||
S.facts = d.facts; S.draft = d.draft;
|
||
$('#facts').textContent = d.facts;
|
||
$('#f-title').value = d.draft.title || '';
|
||
$('#f-subtitle').value = d.draft.subtitle || '';
|
||
$('#f-body').value = d.draft.body || '';
|
||
$('#f-alt').value = d.draft.image_alt || '';
|
||
$('#cap-out').hidden = false;
|
||
$('#cap-status').textContent = d.warning ? ('사진 판독 대신 메모로 썼습니다: ' + d.warning) : '';
|
||
}catch(e){ $('#cap-status').innerHTML = `<span class="status err">${e.message}</span>`; }
|
||
finally{ $('#cap').disabled = false; }
|
||
};
|
||
|
||
/* ---------- 음성 입력 ---------- */
|
||
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||
(() => {
|
||
const btn = $('#voice');
|
||
if (!SR || !window.isSecureContext){ btn.textContent = '🎙 키보드의 마이크 버튼으로도 말할 수 있습니다'; btn.disabled = true; return; }
|
||
const rec = new SR(); rec.lang='ko-KR'; rec.interimResults=false; rec.continuous=false;
|
||
let on = false;
|
||
rec.onresult = ev => {
|
||
const text = Array.from(ev.results).map(r=>r[0].transcript).join(' ');
|
||
const t = $('#note'); t.value = (t.value ? t.value + ' ' : '') + text; t.focus();
|
||
};
|
||
rec.onend = () => { on=false; btn.classList.remove('rec'); btn.textContent='🎙 말로 적기'; };
|
||
rec.onerror = () => toast('음성 인식을 쓰지 못했습니다. 키보드 마이크를 써보세요');
|
||
btn.onclick = () => { if (on){ rec.stop(); return; } rec.start(); on=true;
|
||
btn.classList.add('rec'); btn.textContent='● 말하는 중… (눌러서 끝내기)'; };
|
||
})();
|
||
|
||
/* ---------- 항목 프리셋 ---------- */
|
||
async function loadPresets(){
|
||
try{
|
||
const d = await api('/api/presets');
|
||
S.presets = d.presets;
|
||
document.querySelectorAll('.chips[data-for]').forEach(box=>{
|
||
const target = box.dataset.for;
|
||
const key = target.endsWith('size') ? 'size'
|
||
: target.endsWith('material') ? 'material' : 'care';
|
||
box.innerHTML = (d.presets[key]||[]).map(v=>`<button class="chip">${v}</button>`).join('');
|
||
box.querySelectorAll('.chip').forEach(ch=>ch.onclick=()=>{
|
||
box.querySelectorAll('.chip').forEach(c=>c.setAttribute('aria-pressed','false'));
|
||
ch.setAttribute('aria-pressed','true');
|
||
$('#'+box.dataset.for).value = ch.textContent;
|
||
});
|
||
});
|
||
}catch(e){ toast(e.message); }
|
||
}
|
||
|
||
/* ---------- 확인·저장 ---------- */
|
||
function payload(){
|
||
return {
|
||
photos: S.photos.map(p=>p.uid),
|
||
slug: (S.draft && S.draft.slug) || '',
|
||
title: $('#f-title').value.trim(),
|
||
subtitle: $('#f-subtitle').value.trim(),
|
||
body: $('#f-body').value.trim(),
|
||
image_alt: $('#f-alt').value.trim(),
|
||
size: $('#f-size').value.trim(),
|
||
material: $('#f-material').value.trim(),
|
||
care: $('#f-care').value.trim(),
|
||
price: $('#f-price').value.trim(),
|
||
price_note: $('#f-pricenote').value.trim(),
|
||
date: $('#f-date').value || new Date().toISOString().slice(0,10),
|
||
naver_url: $('#f-naver').value.trim(),
|
||
featured: $('#f-featured').checked,
|
||
sold_out: $('#f-soldout').checked,
|
||
force_deploy: $('#force').checked
|
||
};
|
||
}
|
||
function renderSummary(){
|
||
const p = payload();
|
||
const price = p.price ? Number(p.price).toLocaleString('ko-KR') + '원' : '가격 문의';
|
||
$('#summary').innerHTML = `
|
||
<div class="summary">
|
||
<b>${p.title || '(제목 없음)'}</b><br>${p.subtitle || ''}<br>
|
||
사진 ${p.photos.length}장 · ${price}<br>
|
||
${p.size ? '규격 ' + p.size + '<br>' : ''}
|
||
${p.material ? '소재 ' + p.material + '<br>' : ''}
|
||
${p.date}
|
||
</div>`;
|
||
}
|
||
async function doPublish(deploy){
|
||
if (S.busy) return; S.busy = true;
|
||
['#pub-deploy','#pub-only'].forEach(s=>$(s).disabled=true);
|
||
$('#pub-status').innerHTML = '<span class="spin"></span> 저장 중… (사진 변환 → 빌드 → 커밋' + (deploy?' → 배포':'') + ')';
|
||
try{
|
||
const d = await api('/api/publish', Object.assign(payload(), {deploy}));
|
||
const tail = d.deployed ? '사이트에 올렸습니다. '
|
||
: (deploy ? '저장은 했지만 배포하지 못했습니다.<br><span class="err">' + (d.deploy_log||'') + '</span>'
|
||
: '저장했습니다. 사이트에는 아직 안 올라갔습니다 — 목록에서 [사이트에 올리기]를 누르세요.');
|
||
$('#pub-status').innerHTML =
|
||
`저장했습니다 — <b>${d.slug}</b> · 커밋 ${String(d.commit).slice(0,40)}<br>` + tail +
|
||
`<a class="live" href="${d.url}" target="_blank">상세 페이지 열기</a>`;
|
||
S.lastSlug = d.slug;
|
||
$('#open-preview').href = d.url;
|
||
const live = $('#open-live');
|
||
if (d.deployed && d.live_url) { live.href = d.live_url; live.hidden = false; } else { live.hidden = true; }
|
||
$('#after-publish').hidden = false;
|
||
toast('등록 완료');
|
||
loadHome();
|
||
}catch(e){ $('#pub-status').innerHTML = `<span class="status err">${e.message}</span>`; }
|
||
finally{ S.busy=false; ['#pub-deploy','#pub-only'].forEach(s=>$(s).disabled=false); }
|
||
}
|
||
$('#pub-deploy').onclick = () => doPublish(true);
|
||
$('#pub-only').onclick = () => doPublish(false);
|
||
$('#to-list').onclick = () => go('home');
|
||
document.querySelector('.brand').onclick = () => go('home');
|
||
|
||
/* ---------- 사이트에 올리기(배포만) ---------- */
|
||
$('#deploy-all').onclick = async () => {
|
||
const status = $('#deploy-status');
|
||
const run = async (force) => {
|
||
status.innerHTML = '<span class="spin"></span> 사이트에 올리는 중…';
|
||
try{
|
||
const d = await api('/api/deploy', {force});
|
||
status.innerHTML = d.ok ? '올렸습니다. ' + (d.log||'').split('\n').pop() : `<span class="err">${d.log||'실패'}</span>`;
|
||
toast('사이트에 올렸습니다');
|
||
loadHome();
|
||
return true;
|
||
}catch(e){
|
||
if (String(e.message).includes('초안')){
|
||
if (confirm(e.message + '\n\n그 초안까지 함께 올릴까요?')) return run(true);
|
||
status.textContent = '취소했습니다';
|
||
return true;
|
||
}
|
||
status.innerHTML = `<span class="status err">${e.message}</span>`;
|
||
return false;
|
||
}
|
||
};
|
||
await run(false);
|
||
};
|
||
|
||
/* ---------- 고치기 ---------- */
|
||
async function openEdit(slug){
|
||
$('#e-status').textContent = ''; $('#edit-up').textContent = '';
|
||
try{
|
||
const d = await api('/api/product?slug=' + encodeURIComponent(slug));
|
||
const p = d.product, f = p.fields || {};
|
||
const gallery = Array.isArray(f.gallery)
|
||
? f.gallery
|
||
: String(f.gallery || '').split('\n').map(s => s.trim()).filter(Boolean);
|
||
S.edit = { slug, images: [f.image, ...gallery].filter(Boolean).map(path => ({ path })) };
|
||
$('#edit-head').textContent = f.title || '작품 고치기';
|
||
$('#edit-slug').textContent = slug;
|
||
$('#edit-open').href = '/p/' + slug + '.html';
|
||
$('#e-title').value = f.title || '';
|
||
$('#e-subtitle').value = f.subtitle || '';
|
||
$('#e-body').value = p.body || '';
|
||
$('#e-alt').value = f.image_alt || '';
|
||
$('#e-size').value = f.size || '';
|
||
$('#e-material').value = f.material || '';
|
||
$('#e-care').value = f.care || '';
|
||
$('#e-price').value = f.price || '';
|
||
$('#e-pricenote').value = f.price_note || '';
|
||
$('#e-date').value = String(f.date || '').slice(0,10);
|
||
$('#e-naver').value = f.naver_url || '';
|
||
$('#e-featured').checked = !!f.featured;
|
||
$('#e-soldout').checked = !!f.sold_out;
|
||
renderEditThumbs();
|
||
go('edit');
|
||
}catch(e){ toast(e.message); }
|
||
}
|
||
|
||
function renderEditThumbs(){
|
||
const box = $('#edit-thumbs');
|
||
const imgs = (S.edit && S.edit.images) || [];
|
||
if (!imgs.length){ box.innerHTML = '<p class="note" style="grid-column:1/-1">사진이 없습니다. 한 장은 있어야 합니다.</p>'; return; }
|
||
box.innerHTML = imgs.map((p,i)=>`
|
||
<div class="thumb">
|
||
<img src="${p.uid ? '/media-inbox/' + p.uid + '.jpg' : '/' + p.path}" alt="">
|
||
${i===0?'<span class="badge">대표</span>':''}
|
||
<div class="tools">
|
||
${i>0?`<button data-mvn="${i}:-1" aria-label="앞으로">←</button>`:''}
|
||
${i<imgs.length-1?`<button data-mvn="${i}:1" aria-label="뒤로">→</button>`:''}
|
||
<button class="del" data-deln="${i}" aria-label="삭제">×</button>
|
||
</div>
|
||
</div>`).join('');
|
||
box.querySelectorAll('[data-deln]').forEach(b=>b.onclick=()=>{
|
||
S.edit.images.splice(+b.dataset.deln,1); renderEditThumbs();
|
||
});
|
||
box.querySelectorAll('[data-mvn]').forEach(b=>b.onclick=()=>{
|
||
const [i,dv] = b.dataset.mvn.split(':').map(Number);
|
||
const j = i + dv; if (j < 0 || j >= S.edit.images.length) return;
|
||
[S.edit.images[i], S.edit.images[j]] = [S.edit.images[j], S.edit.images[i]];
|
||
renderEditThumbs();
|
||
});
|
||
}
|
||
|
||
$('#edit-shoot').onclick = () => $('#edit-cam').click();
|
||
$('#edit-album-btn').onclick = () => $('#edit-album').click();
|
||
$('#edit-cam').onchange = e => uploadEditFiles(e.target.files);
|
||
$('#edit-album').onchange = e => uploadEditFiles(e.target.files);
|
||
|
||
async function uploadEditFiles(files){
|
||
const list = Array.from(files || []);
|
||
if (!list.length) return;
|
||
for (let i=0;i<list.length;i++){
|
||
$('#edit-up').innerHTML = `<span class="spin"></span> 사진 올리는 중 ${i+1}/${list.length}`;
|
||
try{
|
||
const res = await fetch('/api/photo?name=' + encodeURIComponent(list[i].name || 'photo.jpg'),
|
||
{method:'POST', headers:{'Content-Type':'application/octet-stream'}, body:list[i]});
|
||
const d = await res.json();
|
||
if (!res.ok || d.ok === false) throw new Error(d.error || '업로드 실패');
|
||
S.edit.images.push({ uid: d.uid });
|
||
}catch(e){ $('#edit-up').innerHTML = `<span class="status err">${e.message}</span>`; return; }
|
||
}
|
||
$('#edit-up').textContent = '';
|
||
$('#edit-cam').value = ''; $('#edit-album').value = '';
|
||
renderEditThumbs();
|
||
}
|
||
|
||
async function saveEdit(deploy){
|
||
const s = $('#e-status');
|
||
if (!$('#e-title').value.trim()){ s.innerHTML = '<span class="err">제목을 넣어 주세요</span>'; return; }
|
||
if (!S.edit || !S.edit.images.length){ s.innerHTML = '<span class="err">사진이 최소 한 장 필요합니다</span>'; return; }
|
||
['#e-save','#e-save-only'].forEach(x=>$(x).disabled=true);
|
||
s.innerHTML = '<span class="spin"></span> 저장 중… (사진 정리 → 빌드 → 커밋' + (deploy?' → 배포':'') + ')';
|
||
try{
|
||
const d = await api('/api/update', {
|
||
slug: S.edit.slug, images: S.edit.images,
|
||
title: $('#e-title').value.trim(), subtitle: $('#e-subtitle').value.trim(),
|
||
body: $('#e-body').value, image_alt: $('#e-alt').value.trim(),
|
||
size: $('#e-size').value.trim(), material: $('#e-material').value.trim(),
|
||
care: $('#e-care').value.trim(), price: $('#e-price').value, price_note: $('#e-pricenote').value.trim(),
|
||
date: $('#e-date').value, naver_url: $('#e-naver').value.trim(),
|
||
featured: $('#e-featured').checked, sold_out: $('#e-soldout').checked, deploy
|
||
});
|
||
s.innerHTML = `고쳤습니다 — 커밋 ${String(d.commit).slice(0,34)}<br>` +
|
||
(d.deployed ? '사이트에 올렸습니다. ' : '저장만 했습니다. ') +
|
||
`<a class="live" href="${d.url}" target="_blank">페이지 열기</a>`;
|
||
toast('수정 완료');
|
||
S.lastSlug = d.slug;
|
||
}catch(e){ s.innerHTML = `<span class="status err">${e.message}</span>`; }
|
||
finally{ ['#e-save','#e-save-only'].forEach(x=>$(x).disabled=false); }
|
||
}
|
||
$('#e-save').onclick = () => saveEdit(true);
|
||
$('#e-save-only').onclick = () => saveEdit(false);
|
||
$('#e-cancel').onclick = () => go('home');
|
||
|
||
/* ---------- 시작 ---------- */
|
||
go('home'); loadPresets();
|
||
</script>
|
||
</body>
|
||
</html>
|