Add multi-source ebook support and per-indexer categories

Introduces granular toggles for Anna's Archive and Indexer Search as ebook sources, updates settings UI to a three-section layout, and documents the new configuration. Adds per-indexer category configuration with separate tabs for audiobooks and ebooks, updates API routes and types for new settings, and ensures legacy config migration. Indexer grouping and file organization logic now support the new category structure and ebook source toggles.
This commit is contained in:
kikootwo
2026-01-30 22:12:24 -05:00
parent 590f089733
commit 5a0cce7985
19 changed files with 563 additions and 212 deletions
+17 -8
View File
@@ -13,8 +13,8 @@ export async function PUT(request: NextRequest) {
return requireAuth(request, async (req: AuthenticatedRequest) => {
return requireAdmin(req, async () => {
try {
// Parse request body
const { enabled, format, baseUrl, flaresolverrUrl } = await request.json();
// Parse request body - new structure with separate source toggles
const { annasArchiveEnabled, indexerSearchEnabled, format, baseUrl, flaresolverrUrl } = await request.json();
// Validate format
const validFormats = ['epub', 'pdf', 'mobi', 'azw3', 'any'];
@@ -25,8 +25,8 @@ export async function PUT(request: NextRequest) {
);
}
// Validate baseUrl (basic check)
if (baseUrl && !baseUrl.startsWith('http')) {
// Validate baseUrl (basic check) - only required if Anna's Archive is enabled
if (annasArchiveEnabled && baseUrl && !baseUrl.startsWith('http')) {
return NextResponse.json(
{ error: 'Base URL must start with http:// or https://' },
{ status: 400 }
@@ -46,23 +46,32 @@ export async function PUT(request: NextRequest) {
const configService = getConfigService();
const configs = [
// New granular source toggles
{
key: 'ebook_sidecar_enabled',
value: enabled ? 'true' : 'false',
key: 'ebook_annas_archive_enabled',
value: annasArchiveEnabled ? 'true' : 'false',
category: 'ebook',
description: 'Enable e-book sidecar downloads from Annas Archive',
description: 'Enable e-book downloads from Anna\'s Archive',
},
{
key: 'ebook_indexer_search_enabled',
value: indexerSearchEnabled ? 'true' : 'false',
category: 'ebook',
description: 'Enable e-book downloads via indexer search (Prowlarr)',
},
// General settings
{
key: 'ebook_sidecar_preferred_format',
value: format || 'epub',
category: 'ebook',
description: 'Preferred e-book format',
},
// Anna's Archive specific settings
{
key: 'ebook_sidecar_base_url',
value: baseUrl || 'https://annas-archive.li',
category: 'ebook',
description: 'Base URL for Annas Archive',
description: 'Base URL for Anna\'s Archive',
},
{
key: 'ebook_sidecar_flaresolverr_url',
@@ -19,7 +19,9 @@ interface SavedIndexerConfig {
seedingTimeMinutes?: number; // Torrents only
removeAfterProcessing?: boolean; // Usenet only
rssEnabled?: boolean;
categories?: number[]; // Array of category IDs (default: [3030] for audiobooks)
audiobookCategories?: number[]; // Array of category IDs for audiobooks (default: [3030])
ebookCategories?: number[]; // Array of category IDs for ebooks (default: [7020])
categories?: number[]; // Legacy field for migration
}
/**
@@ -54,6 +56,12 @@ export async function GET(request: NextRequest) {
const isAdded = !!saved;
const isTorrent = indexer.protocol?.toLowerCase() === 'torrent';
// Migration: if old 'categories' field exists but new fields don't, migrate
const migratedAudiobookCategories = saved?.audiobookCategories ||
saved?.categories || // Legacy migration
[3030]; // Default to audiobooks category
const migratedEbookCategories = saved?.ebookCategories || [7020]; // Default to ebooks category
const config: any = {
id: indexer.id,
name: indexer.name,
@@ -63,7 +71,8 @@ export async function GET(request: NextRequest) {
isAdded, // Explicit flag for UI (new card-based interface)
priority: saved?.priority || 10,
rssEnabled: saved?.rssEnabled ?? false,
categories: saved?.categories || [3030], // Default to audiobooks category
audiobookCategories: migratedAudiobookCategories,
ebookCategories: migratedEbookCategories,
supportsRss: indexer.capabilities?.supportsRss !== false, // Default to true if not specified
};
@@ -117,7 +126,8 @@ export async function PUT(request: NextRequest) {
protocol: indexer.protocol,
priority: indexer.priority,
rssEnabled: indexer.rssEnabled || false,
categories: indexer.categories || [3030], // Default to audiobooks if not specified
audiobookCategories: indexer.audiobookCategories || [3030], // Default to audiobooks
ebookCategories: indexer.ebookCategories || [7020], // Default to ebooks
};
// Add protocol-specific fields
+8 -2
View File
@@ -100,10 +100,16 @@ export async function GET(request: NextRequest) {
chapterMergingEnabled: configMap.get('chapter_merging_enabled') === 'true',
},
ebook: {
enabled: configMap.get('ebook_sidecar_enabled') === 'true',
preferredFormat: configMap.get('ebook_sidecar_preferred_format') || 'epub',
// New granular source toggles (with migration from legacy ebook_sidecar_enabled)
annasArchiveEnabled: configMap.get('ebook_annas_archive_enabled') === 'true' ||
// Migration: if old key is true and new key doesn't exist, use old value
(configMap.get('ebook_annas_archive_enabled') === undefined && configMap.get('ebook_sidecar_enabled') === 'true'),
indexerSearchEnabled: configMap.get('ebook_indexer_search_enabled') === 'true',
// Anna's Archive specific settings
baseUrl: configMap.get('ebook_sidecar_base_url') || 'https://annas-archive.li',
flaresolverrUrl: configMap.get('ebook_sidecar_flaresolverr_url') || '',
// General settings
preferredFormat: configMap.get('ebook_sidecar_preferred_format') || 'epub',
},
general: {
appName: configMap.get('app_name') || 'ReadMeABook',
+22 -6
View File
@@ -22,14 +22,30 @@ export async function POST(
try {
const { id: parentRequestId } = await params;
// Check if e-book sidecar is enabled
const ebookEnabledConfig = await prisma.configuration.findUnique({
where: { key: 'ebook_sidecar_enabled' },
});
// Check which ebook sources are enabled
const [annasArchiveConfig, indexerSearchConfig, legacyConfig] = await Promise.all([
prisma.configuration.findUnique({ where: { key: 'ebook_annas_archive_enabled' } }),
prisma.configuration.findUnique({ where: { key: 'ebook_indexer_search_enabled' } }),
prisma.configuration.findUnique({ where: { key: 'ebook_sidecar_enabled' } }),
]);
if (ebookEnabledConfig?.value !== 'true') {
// Legacy migration: check old key if new keys don't exist
const isAnnasArchiveEnabled = annasArchiveConfig?.value === 'true' ||
(annasArchiveConfig === null && legacyConfig?.value === 'true');
const isIndexerSearchEnabled = indexerSearchConfig?.value === 'true';
// If no sources are enabled, return error
if (!isAnnasArchiveEnabled && !isIndexerSearchEnabled) {
return NextResponse.json(
{ error: 'E-book sidecar feature is not enabled' },
{ error: 'E-book sidecar feature is not enabled (no sources configured)' },
{ status: 400 }
);
}
// If only indexer search is enabled (not yet implemented), return error
if (!isAnnasArchiveEnabled && isIndexerSearchEnabled) {
return NextResponse.json(
{ error: 'E-book indexer search is not yet implemented. Enable Anna\'s Archive to fetch e-books.' },
{ status: 400 }
);
}