diff --git a/app/api/documents.py b/app/api/documents.py index 02af95c..a57cd5c 100644 --- a/app/api/documents.py +++ b/app/api/documents.py @@ -380,10 +380,25 @@ async def delete_document( raise HTTPException(status_code=404, detail="문서를 찾을 수 없습니다") if delete_file: + # 원본 파일 삭제 file_path = Path(settings.nas_mount_path) / doc.file_path if file_path.exists(): file_path.unlink() + # 변환본 삭제 + if doc.original_path: + orig = Path(settings.nas_mount_path) / doc.original_path + if orig.exists(): + orig.unlink() + # preview 캐시 삭제 + preview = Path(settings.nas_mount_path) / "PKM" / ".preview" / f"{doc_id}.pdf" + if preview.exists(): + preview.unlink() + # 관련 processing_queue 먼저 삭제 (FK 제약) + from sqlalchemy import delete as sql_delete + await session.execute( + sql_delete(ProcessingQueue).where(ProcessingQueue.document_id == doc_id) + ) await session.delete(doc) await session.commit()