mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 21:00:09 +00:00
Add authors pages and requestType notifications
Introduce full authors browsing/detail feature and enhance notifications to support type-specific titles. - Add server APIs: authors search, author detail, and author books routes (audnexus integration) that require auth and enrich results with library matches. - Add frontend pages/components: /authors listing and /authors/[asin] detail pages; AuthorCard, AuthorGrid, AuthorDetailCard, SimilarAuthorsRow, and related skeletons. - Add hook and integration stubs: new useAuthors hook and audnexus-authors integration; update audible service to expose audibleBaseUrl. - Update AudiobookDetailsModal to use audibleBaseUrl and link author names to author detail pages. - Add header navigation link to Authors. - Notifications: extend docs and code to include requestType (audiobook|ebook), add getEventTitle/getEventMeta helpers, update queue signature and providers/processors/tests to pass/handle requestType so titles can be resolved per request type. - Misc: job queue, processors, provider tests and notification tests updated to reflect new behavior. This change enables browsing authors and provides type-aware notification titles without per-provider changes.
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Component: Author Search API Route
|
||||
* Documentation: documentation/integrations/audible.md
|
||||
*/
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getCurrentUser } from '@/lib/middleware/auth';
|
||||
import { getConfigService } from '@/lib/services/config.service';
|
||||
import { AUDIBLE_REGIONS, DEFAULT_AUDIBLE_REGION, AudibleRegion } from '@/lib/types/audible';
|
||||
import { RMABLogger } from '@/lib/utils/logger';
|
||||
import {
|
||||
AudnexusAuthorDetail,
|
||||
searchAuthors,
|
||||
fetchAuthorDetail,
|
||||
} from '@/lib/integrations/audnexus-authors';
|
||||
|
||||
const logger = RMABLogger.create('API.Authors.Search');
|
||||
|
||||
/**
|
||||
* GET /api/authors/search?name=Brandon Sanderson
|
||||
* Search for authors on Audnexus, deduplicate, and return enriched details
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
// Require authentication
|
||||
const currentUser = getCurrentUser(request);
|
||||
if (!currentUser) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Unauthorized', message: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const name = request.nextUrl.searchParams.get('name');
|
||||
|
||||
if (!name || name.trim().length === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'ValidationError', message: 'Author name is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Get configured Audible region
|
||||
const configService = getConfigService();
|
||||
const audibleRegion: AudibleRegion = await configService.getAudibleRegion();
|
||||
const region = AUDIBLE_REGIONS[audibleRegion]?.audnexusParam || AUDIBLE_REGIONS[DEFAULT_AUDIBLE_REGION].audnexusParam;
|
||||
|
||||
logger.info(`Searching authors: "${name}" (region: ${region})`);
|
||||
|
||||
// Step 1: Search for authors (returns list with potential duplicates)
|
||||
const searchResults = await searchAuthors(name.trim(), region);
|
||||
|
||||
if (searchResults.length === 0) {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
authors: [],
|
||||
query: name.trim(),
|
||||
});
|
||||
}
|
||||
|
||||
// Step 2: Fetch details for all unique authors in parallel
|
||||
const detailPromises = searchResults.map(author => fetchAuthorDetail(author.asin, region));
|
||||
const detailResults = await Promise.all(detailPromises);
|
||||
|
||||
// Step 3: Build enriched results, filtering out any failed fetches
|
||||
const authors = detailResults
|
||||
.filter((detail): detail is AudnexusAuthorDetail => detail !== null)
|
||||
.map(detail => ({
|
||||
asin: detail.asin,
|
||||
name: detail.name,
|
||||
description: detail.description || undefined,
|
||||
image: detail.image || undefined,
|
||||
genres: detail.genres?.map(g => g.name).slice(0, 3) || [],
|
||||
similarCount: detail.similar?.length || 0,
|
||||
}));
|
||||
|
||||
logger.info(`Author search complete: "${name}" → ${authors.length} results`);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
authors,
|
||||
query: name.trim(),
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to search authors', { error: error instanceof Error ? error.message : String(error) });
|
||||
return NextResponse.json(
|
||||
{ error: 'SearchError', message: 'Failed to search authors' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user