fix: LibreOffice 한글 파일명 호환 — 영문 임시파일로 복사 후 변환

extract_worker, preview_worker 모두 적용.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-04-03 11:18:06 +09:00
parent 45448b4036
commit b37043d651
2 changed files with 17 additions and 5 deletions

View File

@@ -71,22 +71,28 @@ async def process(document_id: int, session: AsyncSession) -> None:
tmp_dir = Path("/tmp/preview_work")
tmp_dir.mkdir(exist_ok=True)
# 한글 파일명 문제 방지 — 영문 임시 파일로 복사
tmp_input = tmp_dir / f"input_{document_id}{source.suffix}"
shutil.copy2(str(source), str(tmp_input))
result = subprocess.run(
[
"libreoffice", "--headless", "--convert-to", "pdf",
"--outdir", str(tmp_dir),
str(source),
str(tmp_input),
],
capture_output=True,
text=True,
timeout=TIMEOUT_SECONDS,
)
tmp_input.unlink(missing_ok=True)
if result.returncode != 0:
raise RuntimeError(f"LibreOffice 변환 실패: {result.stderr[:200]}")
# 변환 결과 찾기
converted = tmp_dir / f"{source.stem}.pdf"
converted = tmp_dir / f"input_{document_id}.pdf"
if not converted.exists():
raise RuntimeError(f"변환 결과물 없음: {converted}")