/** * Component: Audiobookshelf Configuration Step * Documentation: documentation/features/audiobookshelf-integration.md */ 'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; interface AudiobookshelfStepProps { absUrl: string; absApiToken: string; absLibraryId: string; absTriggerScanAfterImport: boolean; absLibraries: Library[]; onUpdate: (field: string, value: any) => void; onNext: () => void; onBack: () => void; } interface Library { id: string; name: string; itemCount: number; } export function AudiobookshelfStep({ absUrl, absApiToken, absLibraryId, absTriggerScanAfterImport, absLibraries, onUpdate, onNext, onBack, }: AudiobookshelfStepProps) { const [testing, setTesting] = useState(false); const [testResult, setTestResult] = useState<{ success: boolean; message?: string; libraries?: Library[]; } | null>( absLibraries.length > 0 ? { success: true, message: 'Connection verified previously.' } : null ); const [libraries, setLibraries] = useState(absLibraries); const testConnection = async () => { setTesting(true); setTestResult(null); try { const response = await fetch('/api/setup/test-abs', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ serverUrl: absUrl, apiToken: absApiToken }), }); const data = await response.json(); if (response.ok && data.success) { const libs = data.libraries || []; setTestResult({ success: true, message: 'Connection successful!', libraries: libs, }); setLibraries(libs); onUpdate('absLibraries', libs); } else { setTestResult({ success: false, message: data.error || 'Connection failed', }); } } catch (error) { setTestResult({ success: false, message: error instanceof Error ? error.message : 'Connection test failed', }); } finally { setTesting(false); } }; const handleNext = () => { if (!testResult?.success) { setTestResult({ success: false, message: 'Please test the connection before proceeding', }); return; } if (!absLibraryId) { setTestResult({ success: false, message: 'Please select an audiobook library', }); return; } onNext(); }; return (

Configure Audiobookshelf

Enter your Audiobookshelf server details and API token.

onUpdate('absUrl', e.target.value)} />

The URL where your Audiobookshelf server is running (include port)

onUpdate('absApiToken', e.target.value)} />

Generate this in Audiobookshelf → Settings → API Keys → Add API Key

{testResult && (
{testResult.success ? ( ) : ( )}

{testResult.success ? 'Success' : 'Error'}

{testResult.message}

)} {libraries.length > 0 && (

Select the library containing your audiobooks

)} {libraries.length > 0 && (
)}

About API Token

Generate an API key in Audiobookshelf by navigating to Settings → API Keys → Add API Key. Give it a descriptive name and copy the generated key to use here.

); }