Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: add dedicated PDF and text viewer pages for library documents

LearningCircuita136ece3733a
diff --git a/src/local_deep_research/research_library/routes/library_routes.py b/src/local_deep_research/research_library/routes/library_routes.py
index 8ef82a162a..13d540ef5c 100644
--- a/src/local_deep_research/research_library/routes/library_routes.py
+++ b/src/local_deep_research/research_library/routes/library_routes.py
@@ -344,12 +344,10 @@ def get_pdf_url(document_id):
)
-@library_bp.route("/api/document/<string:document_id>/pdf")
+@library_bp.route("/document/<string:document_id>/pdf")
@login_required
-def serve_pdf(document_id):
- """Serve PDF file for viewing."""
- from loguru import logger
-
+def view_pdf_page(document_id):
+ """Page for viewing PDF file."""
username = session.get("username")
service = LibraryService(username)
@@ -389,11 +387,67 @@ def serve_pdf(document_id):
return "PDF file not found", 404
+@library_bp.route("/api/document/<string:document_id>/pdf")
+@login_required
+def serve_pdf_api(document_id):
+ """API endpoint for serving PDF file (kept for backward compatibility)."""
+ return view_pdf_page(document_id)
+
+
+@library_bp.route("/document/<string:document_id>/txt")
+@login_required
+def view_text_page(document_id):
+ """Page for viewing text content."""
+ from ...database.models.library import LibraryTextDocument
+ from ...database.session_context import get_user_db_session
+
+ username = session.get("username")
+
+ with get_user_db_session(username) as db_session:
+ # Try to get text document by document_id (PDF with extracted text)
+ text_doc = (
+ db_session.query(LibraryTextDocument)
+ .filter_by(document_id=document_id)
+ .first()
+ )
+
+ # If not found, try by LibraryTextDocument.id (text-only document)
+ if not text_doc:
+ text_doc = (
+ db_session.query(LibraryTextDocument)
+ .filter_by(id=document_id)
+ .first()
+ )
+
+ if not text_doc:
+ logger.warning(
+ f"Text document not found for document ID {document_id}"
+ )
+ return "Text not found", 404
+
+ if not text_doc.text_content:
+ logger.warning(f"Text document {document_id} has no text content")
+ return "Text content not available", 404
+
+ logger.info(
+ f"Serving text content for document {document_id}: {len(text_doc.text_content)} characters"
+ )
+
+ # Render as HTML page
+ return render_template_with_defaults(
+ "pages/document_text.html",
+ document_id=document_id,
+ title=text_doc.title or "Document Text",
+ text_content=text_doc.text_content,
+ extraction_method=text_doc.extraction_method,
+ word_count=text_doc.word_count,
+ )
+
+
@library_bp.route("/api/document/<string:document_id>/text")
@login_required
-def serve_text(document_id):
- """Serve text content from database for viewing."""
- from loguru import logger
+def serve_text_api(document_id):
+ """API endpoint for serving text content (kept for backward compatibility)."""
from ...database.models.library import LibraryTextDocument
from ...database.session_context import get_user_db_session
diff --git a/src/local_deep_research/web/templates/pages/document_details.html b/src/local_deep_research/web/templates/pages/document_details.html
index d64c2463fa..993ccd88f5 100644
--- a/src/local_deep_research/web/templates/pages/document_details.html
+++ b/src/local_deep_research/web/templates/pages/document_details.html
@@ -27,16 +27,16 @@
{% endif %}
<div class="ldr-document-actions">
- {% if document.file_exists and document.file_absolute_path %}
- <a href="/library/api/document/{{ document.id }}/pdf" target="_blank" class="ldr-btn ldr-btn-primary">
+ {% if document.file_absolute_path or document.is_pdf %}
+ <a href="/library/document/{{ document.id }}/pdf" target="_blank" class="ldr-btn ldr-btn-primary">
<i class="fas fa-file-pdf"></i> View PDF
</a>
{% endif %}
{% if document.has_text_db %}
- <button onclick="viewText()" class="ldr-btn ldr-btn-success">
+ <a href="/library/document/{{ document.id }}/txt" target="_blank" class="ldr-btn ldr-btn-success">
<i class="fas fa-file-alt"></i> View Text
- </button>
+ </a>
{% endif %}
{% if document.original_url %}
@@ -234,65 +234,4 @@
{% endif %}
</div>
-<script>
-function viewText() {
- fetch('/library/api/document/{{ document.id }}/text')
- .then(response => response.json())
- .then(data => {
- if (data.text_content) {
- // Open text in a new window or modal
- const textWindow = window.open('', '_blank');
- textWindow.document.write(`
- <!DOCTYPE html>
- <html>
- <head>
- <title>${data.title || 'Document Text'}</title>
- <style>
- body {
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
- max-width: 900px;
- margin: 40px auto;
- padding: 20px;
- line-height: 1.6;
- }
- pre {
- white-space: pre-wrap;
- word-wrap: break-word;
- font-family: inherit;
- }
- .ldr-header {
- border-bottom: 2px solid #007bff;
- padding-bottom: 10px;
- margin-bottom: 20px;
- }
- .ldr-meta {
- color: #6c757d;
- font-size: 14px;
- margin-bottom: 20px;
- }
- </style>
- </head>
- <body>
- <div class="ldr-header">
- <h1>${data.title || 'Document Text'}</h1>
- </div>
- <div class="ldr-meta">
- <strong>Extraction Method:</strong> ${data.extraction_method || 'Unknown'}<br>
- <strong>Word Count:</strong> ${data.word_count || 'Unknown'}
- </div>
- <pre>${data.text_content}</pre>
- </body>
- </html>
- `);
- textWindow.document.close();
- } else {
- alert('Text content not available');
- }
- })
- .catch(error => {
- console.error('Error fetching text:', error);
- alert('Failed to load text content');
- });
-}
-</script>
{% endblock %}
diff --git a/src/local_deep_research/web/templates/pages/document_text.html b/src/local_deep_research/web/templates/pages/document_text.html
new file mode 100644
index 0000000000..f31987406b
--- /dev/null
+++ b/src/local_deep_research/web/templates/pages/document_text.html
@@ -0,0 +1,106 @@
+{% extends "base.html" %}
+
+{% block extra_head %}
+<style>
+ body {
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
+ background-color: var(--ldr-bg-color, #f8f9fa);
+ }
+ .ldr-text-container {
+ max-width: 900px;
+ margin: 40px auto;
+ padding: 20px;
+ background: white;
+ border-radius: 8px;
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
+ }
+ .ldr-text-header {
+ border-bottom: 2px solid #007bff;
+ padding-bottom: 15px;
+ margin-bottom: 25px;
+ }
+ .ldr-text-header h1 {
+ margin: 0 0 10px 0;
+ font-size: 28px;
+ color: #212529;
+ }
+ .ldr-text-meta {
+ color: #6c757d;
+ font-size: 14px;
+ margin-bottom: 15px;
+ }
+ .ldr-text-meta-item {
+ display: inline-block;
+ margin-right: 20px;
+ }
+ .ldr-text-actions {
+ margin-bottom: 20px;
+ }
+ .ldr-btn {
+ display: inline-block;
+ padding: 8px 16px;
+ margin-right: 10px;
+ border: none;
+ border-radius: 4px;
+ text-decoration: none;
+ font-size: 14px;
+ cursor: pointer;
+ transition: all 0.2s;
+ }
+ .ldr-btn-primary {
+ background-color: #007bff;
+ color: white;
+ }
+ .ldr-btn-primary:hover {
+ background-color: #0056b3;
+ color: white;
+ }
+ .ldr-btn-secondary {
+ background-color: #6c757d;
+ color: white;
+ }
+ .ldr-btn-secondary:hover {
+ background-color: #545b62;
+ color: white;
+ }
+ .ldr-text-content {
+ white-space: pre-wrap;
+ word-wrap: break-word;
+ font-family: inherit;
+ line-height: 1.6;
+ color: #212529;
+ font-size: 16px;
+ }
+</style>
+{% endblock %}
+
+{% block content %}
+<div class="ldr-text-container">
+ <div class="ldr-text-header">
+ <h1>{{ title }}</h1>
+ <div class="ldr-text-meta">
+ {% if extraction_method %}
+ <span class="ldr-text-meta-item">
+ <strong>Extraction Method:</strong> {{ extraction_method }}
+ </span>
+ {% endif %}
+ {% if word_count %}
+ <span class="ldr-text-meta-item">
+ <strong>Word Count:</strong> {{ "{:,}".format(word_count | int) }}
+ </span>
+ {% endif %}
+ </div>
+ </div>
+
+ <div class="ldr-text-actions">
+ <a href="/library/document/{{ document_id }}" class="ldr-btn ldr-btn-secondary">
+ <i class="fas fa-arrow-left"></i> Back to Document Details
+ </a>
+ <a href="/library" class="ldr-btn ldr-btn-secondary">
+ <i class="fas fa-home"></i> Back to Library
+ </a>
+ </div>
+
+ <div class="ldr-text-content">{{ text_content }}</div>
+</div>
+{% endblock %}
diff --git a/src/local_deep_research/web/templates/pages/library.html b/src/local_deep_research/web/templates/pages/library.html
index aa137cf150..2db858f2ac 100644
--- a/src/local_deep_research/web/templates/pages/library.html
+++ b/src/local_deep_research/web/templates/pages/library.html
@@ -194,31 +194,26 @@
</div>
<!-- Card Body -->
- <div class="card-body" {% if doc.has_pdf or doc.has_text_db %}onclick="window.location.href='/library/document/{{ doc.id }}'"{% else %}style="cursor: not-allowed; opacity: 0.6;"{% endif %}>
- <!-- Storage availability badges -->
- <div class="ldr-storage-badges">
+ <div class="card-body" onclick="window.location.href='/library/document/{{ doc.id }}'">
+ <!-- Large action buttons -->
+ <div class="ldr-action-buttons" onclick="event.stopPropagation()">
{% if doc.has_pdf %}
- <div class="ldr-storage-badge ldr-storage-badge-pdf">
- <i class="fas fa-file-pdf"></i> PDF Available
- </div>
- {% endif %}
- {% if doc.has_text_rag %}
- <div class="ldr-storage-badge ldr-storage-badge-rag">
- <i class="fas fa-file-alt"></i> Text for RAG
- </div>
+ <a href="/library/document/{{ doc.id }}/pdf" target="_blank" class="ldr-action-btn ldr-action-btn-pdf">
+ <i class="fas fa-file-pdf"></i> View PDF
+ </a>
{% endif %}
{% if doc.has_text_db %}
- <div class="ldr-storage-badge ldr-storage-badge-db">
- <i class="fas fa-database"></i> Text in DB
- </div>
+ <a href="/library/document/{{ doc.id }}/txt" target="_blank" class="ldr-action-btn ldr-action-btn-txt">
+ <i class="fas fa-file-alt"></i> View Text
+ </a>
{% endif %}
{% if doc.has_rag_indexed %}
- <div class="ldr-storage-badge ldr-storage-badge-rag-indexed" title="{{ doc.rag_chunk_count }} chunks indexed">
- <i class="fas fa-brain"></i> RAG Indexed ({{ doc.rag_chunk_count }} chunks)
+ <div class="ldr-action-btn ldr-action-btn-rag" title="{{ doc.rag_chunk_count }} chunks indexed">
+ <i class="fas fa-brain"></i> RAG Indexed
</div>
{% endif %}
- {% if not doc.has_pdf and not doc.has_text_rag and not doc.has_text_db %}
- <div class="ldr-storage-badge ldr-storage-badge-none">
+ {% if not doc.has_pdf and not doc.has_text_db %}
+ <div class="ldr-action-btn ldr-action-btn-none">
<i class="fas fa-exclamation-triangle"></i> Not Downloaded
</div>
{% endif %}
@@ -248,19 +243,6 @@
{% endif %}
</div>
- <!-- Download Location (collapsible) -->
- <details class="file-location">
- <summary>
- <i class="fas fa-folder-open"></i> File Location
- </summary>
- <div class="location-info">
- <code>{{ doc.file_absolute_path }}</code>
- <button class="btn-sm" onclick="copyPath('{{ doc.file_absolute_path }}')">
- <i class="fas fa-copy"></i>
- </button>
- </div>
- </details>
-
<!-- Research Info -->
<div class="research-info">
<span class="research-link">
@@ -695,48 +677,66 @@
position: relative;
}
-/* Storage availability badges */
-.ldr-storage-badges {
+/* Large action buttons */
+.ldr-action-buttons {
display: flex;
flex-wrap: wrap;
- gap: 6px;
- margin-bottom: 12px;
+ gap: 8px;
+ margin-bottom: 15px;
}
-.ldr-storage-badge {
- padding: 4px 8px;
- border-radius: 4px;
- font-size: 10px;
+.ldr-action-btn {
+ padding: 10px 16px;
+ border-radius: 6px;
+ font-size: 14px;
font-weight: 600;
display: inline-flex;
align-items: center;
- gap: 4px;
+ gap: 8px;
white-space: nowrap;
+ text-decoration: none;
+ transition: all 0.2s;
+ cursor: pointer;
+ flex: 1;
+ min-width: 120px;
+ justify-content: center;
}
-.ldr-storage-badge-pdf {
+.ldr-action-btn-pdf {
background: #dc3545;
color: white;
}
-.ldr-storage-badge-rag {
- background: #ffc107;
- color: #212529;
+.ldr-action-btn-pdf:hover {
+ background: #c82333;
+ transform: translateY(-2px);
+ box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
+ color: white;
}
-.ldr-storage-badge-db {
+.ldr-action-btn-txt {
background: #17a2b8;
color: white;
}
-.ldr-storage-badge-rag-indexed {
+.ldr-action-btn-txt:hover {
+ background: #138496;
+ transform: translateY(-2px);
+ box-shadow: 0 4px 12px rgba(23, 162, 184, 0.4);
+ color: white;
+}
+
+.ldr-action-btn-rag {
background: #6f42c1;
color: white;
+ cursor: default;
}
-.ldr-storage-badge-none {
- background: #ff9800;
+.ldr-action-btn-none {
+ background: #6c757d;
color: white;
+ cursor: default;
+ opacity: 0.7;
}
.doc-title {