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.

Fix library document viewing and dark theme issues

LearningCircuitc797d941bd3d
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.py
index ecc19f50ff..54559d9b10 100644
--- a/src/local_deep_research/research_library/services/library_service.py
+++ b/src/local_deep_research/research_library/services/library_service.py
@@ -585,9 +585,10 @@ class LibraryService:
Get a specific document by its ID.
Returns document information with file path.
+ Searches both LibraryDocument (PDFs) and LibraryTextDocument (text-only).
"""
with get_user_db_session(self.username) as session:
- # Query for the specific document
+ # First try to find PDF document (LibraryDocument)
result = (
session.query(
LibraryDocument, ResearchResource, ResearchHistory
@@ -604,53 +605,124 @@ class LibraryService:
.first()
)
- if not result:
- return None
+ if result:
+ # Found PDF document
+ doc, resource, research = result
- doc, resource, research = result
+ # Get download tracker info
+ tracker = (
+ session.query(DownloadTracker)
+ .filter_by(url_hash=self._get_url_hash(resource.url))
+ .first()
+ )
- # Get download tracker info
- tracker = (
- session.query(DownloadTracker)
- .filter_by(url_hash=self._get_url_hash(resource.url))
+ return {
+ "id": doc.id,
+ "resource_id": doc.resource_id,
+ "research_id": doc.research_id,
+ "document_title": doc.title or resource.title,
+ "original_url": doc.original_url or resource.url,
+ "file_path": doc.file_path,
+ "file_absolute_path": str(
+ get_absolute_path_from_settings(tracker.file_path)
+ )
+ if tracker and tracker.file_path
+ else (
+ None
+ if doc.file_path == "metadata_only"
+ else doc.file_path
+ ),
+ "file_name": Path(doc.file_path).name
+ if doc.file_path and doc.file_path != "metadata_only"
+ else None,
+ "file_size": doc.file_size,
+ "file_type": doc.file_type,
+ "mime_type": doc.mime_type,
+ "domain": self._extract_domain(resource.url),
+ "download_status": doc.download_status,
+ "downloaded_at": doc.downloaded_at.isoformat()
+ if doc.downloaded_at
+ and hasattr(doc.downloaded_at, "isoformat")
+ else str(doc.downloaded_at)
+ if doc.downloaded_at
+ else None,
+ "favorite": doc.favorite,
+ "tags": doc.tags,
+ "research_title": research.query[:100],
+ "research_created_at": research.created_at
+ if isinstance(research.created_at, str)
+ else research.created_at.isoformat()
+ if research.created_at
+ else None,
+ # PDF-specific fields
+ "is_pdf": True,
+ "has_text_db": bool(
+ session.query(LibraryTextDocument)
+ .filter_by(document_id=doc_id)
+ .first()
+ ),
+ }
+
+ # If not found in LibraryDocument, try LibraryTextDocument (text-only)
+ text_result = (
+ session.query(
+ LibraryTextDocument, ResearchResource, ResearchHistory
+ )
+ .join(
+ ResearchResource,
+ LibraryTextDocument.resource_id == ResearchResource.id,
+ )
+ .join(
+ ResearchHistory,
+ LibraryTextDocument.research_id == ResearchHistory.id,
+ )
+ .filter(LibraryTextDocument.id == doc_id)
.first()
)
- return {
- "id": doc.id,
- "resource_id": doc.resource_id,
- "research_id": doc.research_id,
- "document_title": doc.title or resource.title,
- "original_url": doc.original_url or resource.url,
- "file_path": doc.file_path,
- "file_absolute_path": str(
- get_absolute_path_from_settings(tracker.file_path)
- )
- if tracker and tracker.file_path
- else (
- None if doc.file_path == "metadata_only" else doc.file_path
- ),
- "file_name": Path(doc.file_path).name
- if doc.file_path and doc.file_path != "metadata_only"
- else None,
- "file_size": doc.file_size,
- "file_type": doc.file_type,
- "mime_type": doc.mime_type,
- "domain": self._extract_domain(resource.url),
- "download_status": doc.download_status,
- "downloaded_at": doc.downloaded_at.isoformat()
- if doc.downloaded_at and hasattr(doc.downloaded_at, "isoformat")
- else str(doc.downloaded_at)
- if doc.downloaded_at
- else None,
- "favorite": doc.favorite,
- "research_title": research.query[:100],
- "research_created_at": research.created_at
- if isinstance(research.created_at, str)
- else research.created_at.isoformat()
- if research.created_at
- else None,
- }
+ if text_result:
+ # Found text-only document
+ text_doc, resource, research = text_result
+
+ return {
+ "id": text_doc.id,
+ "resource_id": text_doc.resource_id,
+ "research_id": text_doc.research_id,
+ "document_title": text_doc.title or resource.title,
+ "original_url": text_doc.original_url or resource.url,
+ "file_path": text_doc.file_path or "text_only",
+ "file_absolute_path": None,
+ "file_name": Path(text_doc.file_path).name
+ if text_doc.file_path
+ else "text_only",
+ "file_size": text_doc.file_size,
+ "file_type": "txt",
+ "mime_type": "text/plain",
+ "domain": self._extract_domain(resource.url),
+ "download_status": text_doc.extraction_status,
+ "downloaded_at": text_doc.extracted_at.isoformat()
+ if text_doc.extracted_at
+ and hasattr(text_doc.extracted_at, "isoformat")
+ else str(text_doc.extracted_at)
+ if text_doc.extracted_at
+ else None,
+ "favorite": False, # Text-only docs don't have favorite flag
+ "tags": None,
+ "research_title": research.query[:100],
+ "research_created_at": research.created_at
+ if isinstance(research.created_at, str)
+ else research.created_at.isoformat()
+ if research.created_at
+ else None,
+ # Text-specific fields
+ "is_pdf": False,
+ "has_text_db": bool(text_doc.text_content),
+ "extraction_method": text_doc.extraction_method,
+ "word_count": text_doc.word_count,
+ }
+
+ # Not found in either table
+ return None
def toggle_favorite(self, document_id: str) -> bool:
"""Toggle favorite status of a document."""
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 4905a64f1e..195c5331d5 100644
--- a/src/local_deep_research/web/templates/pages/document_details.html
+++ b/src/local_deep_research/web/templates/pages/document_details.html
@@ -16,12 +16,12 @@
font-size: 28px;
font-weight: 600;
margin-bottom: 10px;
- color: var(--ldr-text-primary, #212529);
+ color: var(--ldr-text-primary, #e4e4e4);
}
.ldr-document-subtitle {
font-size: 16px;
- color: var(--ldr-text-secondary, #6c757d);
+ color: var(--ldr-text-secondary, #a0a0a0);
margin-bottom: 15px;
}
@@ -33,8 +33,8 @@
}
.ldr-metadata-section {
- background-color: var(--ldr-card-bg, #ffffff);
- border: 1px solid var(--ldr-border-color, #dee2e6);
+ background-color: var(--ldr-card-bg, #2a2a2a);
+ border: 1px solid var(--ldr-border-color, #333);
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
@@ -44,7 +44,7 @@
font-size: 20px;
font-weight: 600;
margin-bottom: 15px;
- color: var(--ldr-text-primary, #212529);
+ color: var(--ldr-text-primary, #e4e4e4);
border-bottom: 2px solid var(--ldr-primary-color, #007bff);
padding-bottom: 10px;
}
@@ -63,14 +63,14 @@
.ldr-metadata-label {
font-weight: 600;
- color: var(--ldr-text-secondary, #6c757d);
+ color: var(--ldr-text-secondary, #a0a0a0);
font-size: 13px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.ldr-metadata-value {
- color: var(--ldr-text-primary, #212529);
+ color: var(--ldr-text-primary, #e4e4e4);
font-size: 15px;
word-break: break-word;
}
@@ -93,18 +93,18 @@
}
.ldr-badge-success {
- background-color: var(--ldr-success-bg, #d4edda);
- color: var(--ldr-success-color, #155724);
+ background-color: var(--ldr-success-bg, #1a3a1f);
+ color: var(--ldr-success-color, #28a745);
}
.ldr-badge-info {
- background-color: var(--ldr-info-bg, #d1ecf1);
- color: var(--ldr-info-color, #0c5460);
+ background-color: var(--ldr-info-bg, #1a2a3a);
+ color: var(--ldr-info-color, #17a2b8);
}
.ldr-badge-warning {
- background-color: var(--ldr-warning-bg, #fff3cd);
- color: var(--ldr-warning-color, #856404);
+ background-color: var(--ldr-warning-bg, #3d3313);
+ color: var(--ldr-warning-color, #ffc107);
}
.ldr-authors-list {
@@ -122,7 +122,7 @@
}
.ldr-content-preview {
- background-color: var(--ldr-bg, #f8f9fa);
+ background-color: var(--ldr-bg, #1a1a1a);
padding: 15px;
border-radius: 4px;
border-left: 3px solid var(--ldr-primary-color, #007bff);
@@ -185,7 +185,7 @@
}
.ldr-empty-value {
- color: var(--ldr-text-secondary, #6c757d);
+ color: var(--ldr-text-secondary, #a0a0a0);
font-style: italic;
}
</style>
@@ -220,7 +220,7 @@
</a>
{% endif %}
- {% if document.has_text %}
+ {% if document.has_text_db %}
<button onclick="viewText()" class="ldr-btn ldr-btn-success">
<i class="fas fa-file-alt"></i> View Text
</button>
@@ -370,7 +370,7 @@
</div>
{% endif %}
- {% if document.has_text %}
+ {% if document.has_text_db %}
<div class="ldr-metadata-item">
<div class="ldr-metadata-label">Text Content</div>
<div class="ldr-metadata-value">