diff --git a/app/api/documents.py b/app/api/documents.py index f390738..ca01a8b 100644 --- a/app/api/documents.py +++ b/app/api/documents.py @@ -1048,6 +1048,19 @@ async def get_document_image_raw( DocumentImage.image_key == image_key, ) ) + if img is None: + # clause-KB: 절-문서는 부모 표준 이미지를 공유(md_content=부모 슬라이스) → parent_id 폴백. + from sqlalchemy import text as sql_text + _par = (await session.execute( + sql_text("SELECT parent_id FROM documents WHERE id = :id").bindparams(id=doc_id) + )).scalar() + if _par is not None: + img = await session.scalar( + select(DocumentImage).where( + DocumentImage.document_id == _par, + DocumentImage.image_key == image_key, + ) + ) if img is None: raise HTTPException(status_code=404, detail="이미지를 찾을 수 없습니다")