Add interactive ebook search & selection

Introduce interactive ebook support: adds two API endpoints to search (interactive-search-ebook) and create/select ebook requests (select-ebook), plus server-side handlers to route Anna's Archive (direct) and indexer (torrent/NZB) downloads. Frontend: extend RequestActionsDropdown and InteractiveTorrentSearchModal to support an "ebook" search mode and selection flow, and add hooks (useInteractiveSearchEbook / useSelectEbook). Settings: add ebook_auto_grab_enabled with UI toggle and enforce disabling when no ebook sources are enabled; settings GET/PUT updated to persist the flag (default = true to preserve behavior). Documentation updated (scheduler, ebook-sidecar, settings pages) and ranking algorithm docs/tests extended to cover ebook-related normalization and matching cases. Includes logging and ranking integration for indexer results and normalization for Anna's Archive handling.
This commit is contained in:
kikootwo
2026-02-02 19:59:58 -05:00
parent c913be5ca2
commit 1afab5d47f
19 changed files with 1339 additions and 115 deletions
@@ -40,6 +40,7 @@ export function RequestActionsDropdown({
}: RequestActionsDropdownProps) {
const [isOpen, setIsOpen] = useState(false);
const [showInteractiveSearch, setShowInteractiveSearch] = useState(false);
const [showInteractiveSearchEbook, setShowInteractiveSearchEbook] = useState(false);
const { containerRef, dropdownRef, positionAbove, style } = useSmartDropdownPosition(isOpen);
// Determine request type
@@ -80,7 +81,7 @@ export function RequestActionsDropdown({
const canViewSource = !!viewSourceUrl &&
['downloading', 'processing', 'downloaded', 'available'].includes(request.status);
// "Try to fetch Ebook" only for audiobook requests
// Ebook actions (Grab Ebook, Interactive Search Ebook) only for audiobook requests
const canFetchEbook = !isEbook && ebookSidecarEnabled && ['downloaded', 'available'].includes(request.status);
// Close dropdown when clicking outside
@@ -114,6 +115,11 @@ export function RequestActionsDropdown({
setShowInteractiveSearch(true);
};
const handleInteractiveSearchEbook = () => {
setIsOpen(false);
setShowInteractiveSearchEbook(true);
};
const handleCancel = async () => {
setIsOpen(false);
if (window.confirm(`Are you sure you want to cancel the request for "${request.title}"?`)) {
@@ -224,7 +230,7 @@ export function RequestActionsDropdown({
</a>
)}
{/* Fetch E-book */}
{/* Grab E-book (automatic) */}
{canFetchEbook && (
<button
onClick={handleFetchEbook}
@@ -244,7 +250,31 @@ export function RequestActionsDropdown({
d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"
/>
</svg>
Try to fetch Ebook
Grab Ebook
</button>
)}
{/* Interactive Search E-book */}
{canFetchEbook && (
<button
onClick={handleInteractiveSearchEbook}
className="w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-2 transition-colors"
role="menuitem"
>
<svg
className="w-4 h-4"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"
/>
</svg>
Interactive Search Ebook
</button>
)}
@@ -332,7 +362,7 @@ export function RequestActionsDropdown({
{/* Dropdown menu (rendered via portal) */}
{typeof window !== 'undefined' && dropdownMenu && createPortal(dropdownMenu, document.body)}
{/* Interactive Search Modal */}
{/* Interactive Search Modal (Audiobook) */}
<InteractiveTorrentSearchModal
isOpen={showInteractiveSearch}
onClose={() => setShowInteractiveSearch(false)}
@@ -342,6 +372,18 @@ export function RequestActionsDropdown({
author: request.author,
}}
/>
{/* Interactive Search Modal (Ebook) */}
<InteractiveTorrentSearchModal
isOpen={showInteractiveSearchEbook}
onClose={() => setShowInteractiveSearchEbook(false)}
requestId={request.requestId}
audiobook={{
title: request.title,
author: request.author,
}}
searchMode="ebook"
/>
</>
);
}
+1
View File
@@ -114,6 +114,7 @@ export interface EbookSettings {
flaresolverrUrl: string;
// General settings (shared across sources)
preferredFormat: string;
autoGrabEnabled: boolean;
}
/**
@@ -231,6 +231,29 @@ export function EbookTab({ ebook, onChange, onSuccess, onError, markAsSaved }: E
EPUB is recommended for most e-readers. "Any format" accepts the first available.
</p>
</div>
{/* Auto Grab Toggle */}
<div className="flex items-start gap-4 pt-2">
<input
type="checkbox"
id="auto-grab-enabled"
checked={ebook.autoGrabEnabled ?? true}
onChange={(e) => updateEbook('autoGrabEnabled', e.target.checked)}
className="mt-1 h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<div className="flex-1">
<label
htmlFor="auto-grab-enabled"
className="block text-sm font-medium text-gray-900 dark:text-gray-100 cursor-pointer"
>
Automatically fetch ebooks
</label>
<p className="text-sm text-gray-600 dark:text-gray-400 mt-1">
When enabled, ebook requests are created automatically after audiobook downloads complete.
When disabled, use the "Fetch Ebook" button on completed requests.
</p>
</div>
</div>
</div>
</div>
)}
@@ -82,6 +82,7 @@ export function useEbookSettings({ ebook, onChange, onSuccess, onError, markAsSa
format: ebook.preferredFormat || 'epub',
baseUrl: ebook.baseUrl || 'https://annas-archive.li',
flaresolverrUrl: ebook.flaresolverrUrl || '',
autoGrabEnabled: ebook.autoGrabEnabled ?? true,
}),
});