Fix wizard re-run: skip existing PDF/text, preserve state across restarts

Server:
- download-pdf-stream: check if PDF already exists (size > 1KB) → return
  cached path immediately, skip all network requests

Client (startPrep):
- save pdfPaths from prepLog before reset → skip PMC download if path known
- skip text extraction if paperTexts[key] already loaded in memory
- text from project open (onOpenProjChange) now survives "다시 실행"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kim
2026-06-02 15:15:08 +09:00
co-authored by Claude Sonnet 4.6
parent 557e328610
commit bba06bab6f
2 changed files with 22 additions and 3 deletions
+15 -3
View File
@@ -1908,7 +1908,11 @@ async function startPrep() {
if(btn.disabled) return; // 이미 실행 중
btn.disabled=true; btn.textContent='진행 중...';
setMsg(2,'준비 중...','var(--brand2)');
const keys=Array.from(selected); prepLog={}; renderProgList(); extractedImages=[];
const keys=Array.from(selected);
// prepLog 리셋 전에 기존 pdfPath 보존 (재실행 시 재다운로드 방지)
const savedPdfPaths={};
for(const k of keys){ if(prepLog[k]?.pdfPath) savedPdfPaths[k]=prepLog[k].pdfPath; }
prepLog={}; renderProgList(); extractedImages=[];
document.getElementById('imgrid').innerHTML='<div style="color:var(--muted);font-size:11px">📷 이미지 캡처 버튼으로 추가하세요</div>';
// 프로젝트 slug 결정 — PDF/이미지를 프로젝트 폴더에 직접 저장 (항상 결정)
@@ -1945,6 +1949,12 @@ async function startPrep() {
prepLog[key].pdf='done'; prepLog[key].pdfPath=pdfPath; updProg(key);
if(!pdfPath){ prepLog[key].img='fail'; prepLog[key].txt='fail'; prepLog[key].error='PDF 경로 확인 불가'; updProg(key); continue; }
setMsg(2,paperLabel(key)+' 이미지 추출...','var(--brand2)');
} else if(savedPdfPaths[key]) {
// 이전 실행에서 다운로드된 PDF — 재다운로드 스킵
pdfPath=savedPdfPaths[key];
prepLog[key].pdf='done'; prepLog[key].pdfPath=pdfPath;
setMsg(2,paperLabel(key)+' PDF 이미 있음 — 스킵','var(--muted)');
updProg(key);
} else {
// PMC 다운로드 (SSE 스트리밍)
setMsg(2,key+' PDF 다운로드...','var(--brand2)');
@@ -2033,8 +2043,10 @@ async function startPrep() {
prepLog[key].img='skip'; updProg(key);
}
// Text extract (토글 ON일 때만)
if(extractText && pdfPath){
// Text extract (토글 ON일 때만, 이미 있으면 스킵)
if(extractText && pdfPath && paperTexts[key]){
prepLog[key].txt='done'; updProg(key); // 이미 로드된 텍스트 유지
} else if(extractText && pdfPath){
prepLog[key].txt='running'; updProg(key);
setMsg(2,paperLabel(key)+' 텍스트 추출...','var(--brand2)');
try{