Fix: PDF 전용 문서 뷰어 처리 개선

- HTML이 없고 PDF만 있는 문서 클릭 시 PDF 매니저로 자동 리다이렉트
- 뷰어에서 HTML 없는 문서의 경우 PDF 뷰어로 자동 전환
- 문서 관리 페이지에서 PDF 전용 문서 처리 로직 개선
- IndentationError 수정으로 백엔드 안정성 향상
This commit is contained in:
hyungi
2025-09-05 13:00:25 +09:00
parent aebce091a9
commit ed36ced994
4 changed files with 119 additions and 35 deletions

View File

@@ -581,6 +581,7 @@ async def get_document_backlinks(
# 2. 노트에서 오는 백링크 (NoteLink) - 동기 쿼리 사용
try:
print(f"🔍 노트 백링크 조회 시작...")
from ...core.database import get_sync_db
sync_db = next(get_sync_db())
@@ -626,8 +627,12 @@ async def get_document_backlinks(
))
sync_db.close()
print(f"✅ 노트 백링크 조회 완료")
except Exception as e:
print(f"❌ 노트 백링크 조회 실패: {e}")
print(f"❌ 오류 타입: {type(e).__name__}")
import traceback
print(f"❌ 스택 트레이스: {traceback.format_exc()}")
print(f"✅ 총 {len(backlinks)}개의 백링크 반환 (문서 + 노트)")
return backlinks

View File

@@ -434,38 +434,65 @@ async def list_user_highlights(
db: AsyncSession = Depends(get_db)
):
"""사용자의 모든 하이라이트 조회"""
query = select(Highlight).options(selectinload(Highlight.user)).where(
Highlight.user_id == current_user.id
)
if document_id:
query = query.where(Highlight.document_id == document_id)
query = query.order_by(Highlight.created_at.desc()).offset(skip).limit(limit)
result = await db.execute(query)
highlights = result.scalars().all()
# 응답 데이터 변환
response_data = []
for highlight in highlights:
highlight_data = HighlightResponse(
id=str(highlight.id),
user_id=str(highlight.user_id),
document_id=str(highlight.document_id),
start_offset=highlight.start_offset,
end_offset=highlight.end_offset,
selected_text=highlight.selected_text,
element_selector=highlight.element_selector,
start_container_xpath=highlight.start_container_xpath,
end_container_xpath=highlight.end_container_xpath,
highlight_color=highlight.highlight_color,
highlight_type=highlight.highlight_type,
created_at=highlight.created_at,
updated_at=highlight.updated_at,
note=None
try:
print(f"🔍 하이라이트 조회 시작 - 사용자: {current_user.email}, document_id: {document_id}")
# 문서 권한이 있는 하이라이트만 조회하도록 Document와 조인
query = select(Highlight).options(selectinload(Highlight.user)).join(
Document, Highlight.document_id == Document.id
).where(
and_(
Highlight.user_id == current_user.id,
# 문서 권한 체크: 관리자이거나 문서 관리 권한이 있거나 공개 문서이거나 본인이 업로드한 문서
or_(
current_user.is_admin == True,
current_user.can_manage_books == True,
Document.is_public == True,
Document.uploaded_by == current_user.id
)
)
)
# 메모는 별도 API에서 조회하므로 여기서는 처리하지 않음
response_data.append(highlight_data)
if document_id:
query = query.where(Highlight.document_id == document_id)
query = query.order_by(Highlight.created_at.desc()).offset(skip).limit(limit)
result = await db.execute(query)
highlights = result.scalars().all()
print(f"✅ 하이라이트 조회 완료: {len(highlights)}")
# 응답 데이터 변환
response_data = []
for highlight in highlights:
highlight_data = HighlightResponse(
id=str(highlight.id),
user_id=str(highlight.user_id),
document_id=str(highlight.document_id),
start_offset=highlight.start_offset,
end_offset=highlight.end_offset,
selected_text=highlight.selected_text,
element_selector=highlight.element_selector,
start_container_xpath=highlight.start_container_xpath,
end_container_xpath=highlight.end_container_xpath,
highlight_color=highlight.highlight_color,
highlight_type=highlight.highlight_type,
created_at=highlight.created_at,
updated_at=highlight.updated_at,
note=None
)
# 메모는 별도 API에서 조회하므로 여기서는 처리하지 않음
response_data.append(highlight_data)
return response_data
return response_data
except Exception as e:
print(f"❌ 하이라이트 조회 실패: {e}")
print(f"❌ 오류 타입: {type(e).__name__}")
import traceback
print(f"❌ 스택 트레이스: {traceback.format_exc()}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Internal server error: {str(e)}"
)