Fix: PDF 전용 문서 뷰어 처리 개선
- HTML이 없고 PDF만 있는 문서 클릭 시 PDF 매니저로 자동 리다이렉트 - 뷰어에서 HTML 없는 문서의 경우 PDF 뷰어로 자동 전환 - 문서 관리 페이지에서 PDF 전용 문서 처리 로직 개선 - IndentationError 수정으로 백엔드 안정성 향상
This commit is contained in:
@@ -341,6 +341,16 @@ window.documentApp = () => ({
|
||||
|
||||
// 문서 보기
|
||||
viewDocument(documentId) {
|
||||
// 문서 정보 찾기
|
||||
const document = this.documents.find(doc => doc.id === documentId);
|
||||
|
||||
// HTML이 없고 PDF만 있는 경우 PDF 매니저로 리다이렉트
|
||||
if (document && !document.html_path && document.pdf_path) {
|
||||
console.log('🔄 PDF 전용 문서 - PDF 매니저로 리다이렉트');
|
||||
window.location.href = `/pdf-manager.html`;
|
||||
return;
|
||||
}
|
||||
|
||||
// 현재 페이지 정보를 세션 스토리지에 저장
|
||||
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
|
||||
sessionStorage.setItem('previousPage', currentPage);
|
||||
|
||||
@@ -55,8 +55,8 @@ class DocumentLoader {
|
||||
// 페이지 제목 업데이트
|
||||
document.title = `${docData.title} - Document Server`;
|
||||
|
||||
// PDF 문서가 아닌 경우에만 HTML 로드
|
||||
if (!docData.pdf_path && docData.html_path) {
|
||||
// HTML 경로가 있는 경우에만 HTML 로드
|
||||
if (docData.html_path) {
|
||||
// HTML 파일 경로 구성 (백엔드 서버를 통해 접근)
|
||||
const htmlPath = docData.html_path;
|
||||
const fileName = htmlPath.split('/').pop();
|
||||
@@ -71,6 +71,25 @@ class DocumentLoader {
|
||||
|
||||
// 문서 내 스크립트 오류 방지를 위한 전역 함수들 정의
|
||||
this.setupDocumentScriptHandlers();
|
||||
} else if (docData.pdf_path) {
|
||||
// HTML이 없고 PDF만 있는 경우 PDF 뷰어로 자동 전환
|
||||
console.log('🔄 HTML이 없는 문서 - PDF 뷰어로 자동 전환');
|
||||
const pdfUrl = `/api/documents/${documentId}/pdf?_token=${this.api.getToken()}`;
|
||||
|
||||
// HTML 컨테이너 숨기기
|
||||
const htmlContainer = document.getElementById('document-content');
|
||||
if (htmlContainer) {
|
||||
htmlContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
// PDF iframe 표시
|
||||
const iframe = document.getElementById('pdf-iframe');
|
||||
if (iframe) {
|
||||
iframe.src = pdfUrl;
|
||||
iframe.style.display = 'block';
|
||||
iframe.style.width = '100%';
|
||||
iframe.style.height = '100vh';
|
||||
}
|
||||
}
|
||||
|
||||
console.log('✅ 문서 로드 완료:', docData.title, docData.pdf_path ? '(PDF)' : '(HTML)');
|
||||
@@ -79,6 +98,29 @@ class DocumentLoader {
|
||||
} catch (error) {
|
||||
console.error('Document load error:', error);
|
||||
|
||||
// HTML 로드 실패 시 PDF로 자동 전환 시도
|
||||
if (docData && docData.pdf_path && !docData.html_path) {
|
||||
console.log('🔄 HTML이 없는 문서 - PDF 뷰어로 자동 전환');
|
||||
// PDF 뷰어로 리다이렉트
|
||||
const currentUrl = new URL(window.location);
|
||||
const pdfUrl = `/api/documents/${documentId}/pdf?_token=${this.api.getToken()}`;
|
||||
|
||||
// iframe에서 PDF 직접 로드
|
||||
const iframe = document.getElementById('pdf-iframe');
|
||||
if (iframe) {
|
||||
iframe.src = pdfUrl;
|
||||
iframe.style.display = 'block';
|
||||
}
|
||||
|
||||
// HTML 컨테이너 숨기기
|
||||
const htmlContainer = document.getElementById('document-content');
|
||||
if (htmlContainer) {
|
||||
htmlContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
return docData;
|
||||
}
|
||||
|
||||
// 백엔드 연결 실패시 목업 데이터로 폴백
|
||||
console.warn('Using fallback mock data');
|
||||
const mockDocument = {
|
||||
|
||||
Reference in New Issue
Block a user