mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
89422fc77a
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.
95 lines
3.0 KiB
TypeScript
95 lines
3.0 KiB
TypeScript
/**
|
|
* Component: Author Detail 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,
|
|
fetchAuthorDetail,
|
|
} from '@/lib/integrations/audnexus-authors';
|
|
|
|
const logger = RMABLogger.create('API.Authors.Detail');
|
|
|
|
const SIMILAR_AUTHORS_LIMIT = 15;
|
|
|
|
/**
|
|
* GET /api/authors/{asin}
|
|
* Fetch author detail from Audnexus with enriched similar author images
|
|
*/
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ asin: string }> }
|
|
) {
|
|
try {
|
|
const currentUser = getCurrentUser(request);
|
|
if (!currentUser) {
|
|
return NextResponse.json(
|
|
{ error: 'Unauthorized', message: 'Authentication required' },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const { asin } = await params;
|
|
|
|
if (!asin || !/^[A-Z0-9]{10}$/.test(asin)) {
|
|
return NextResponse.json(
|
|
{ error: 'ValidationError', message: 'Valid author ASIN is required' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const configService = getConfigService();
|
|
const audibleRegion: AudibleRegion = await configService.getAudibleRegion();
|
|
const regionConfig = AUDIBLE_REGIONS[audibleRegion] || AUDIBLE_REGIONS[DEFAULT_AUDIBLE_REGION];
|
|
const region = regionConfig.audnexusParam;
|
|
|
|
logger.info(`Fetching author detail: ${asin} (region: ${region})`);
|
|
|
|
// Fetch the primary author detail
|
|
const detail = await fetchAuthorDetail(asin, region);
|
|
if (!detail) {
|
|
return NextResponse.json(
|
|
{ error: 'NotFound', message: 'Author not found' },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
// Fetch images for similar authors in parallel (capped)
|
|
const similarSlice = (detail.similar || []).slice(0, SIMILAR_AUTHORS_LIMIT);
|
|
const similarDetails = await Promise.all(
|
|
similarSlice.map(s => fetchAuthorDetail(s.asin, region))
|
|
);
|
|
|
|
const similarAuthors = similarSlice.map((s, i) => ({
|
|
asin: s.asin,
|
|
name: s.name,
|
|
image: similarDetails[i]?.image || undefined,
|
|
}));
|
|
|
|
const author = {
|
|
asin: detail.asin,
|
|
name: detail.name,
|
|
description: detail.description || undefined,
|
|
image: detail.image || undefined,
|
|
genres: detail.genres?.map(g => g.name) || [],
|
|
similar: similarAuthors,
|
|
audibleUrl: `${regionConfig.baseUrl}/author/${asin}`,
|
|
};
|
|
|
|
logger.info(`Author detail complete: "${detail.name}" (${similarAuthors.length} similar authors)`);
|
|
|
|
return NextResponse.json({ success: true, author });
|
|
} catch (error) {
|
|
logger.error('Failed to fetch author detail', { error: error instanceof Error ? error.message : String(error) });
|
|
return NextResponse.json(
|
|
{ error: 'FetchError', message: 'Failed to fetch author details' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|