Fix Audible regional search and links#637
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e90b32a4e8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR fixes Audible region/locale handling end-to-end so searches and metadata lookups consistently use the configured/ad-hoc region, send regional locale headers to Audible’s API, and generate region-correct Audible/Amazon product/source links across the API and SPA.
Changes:
- Thread region + language through backend search flows (controller → search service → ASIN handler → metadata conversion) and persist ASIN region when adding to library.
- Ensure Audible API calls include regional locale headers, and normalize emitted product/source URLs to regional domains.
- Add/adjust backend + frontend regression tests, plus Add New UI region selectors and language defaulting based on selected region.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Features/Api/Services/SearchServiceFixesTests.cs | Adds regression test ensuring ASIN search uses requested region for Audible source/product links. |
| tests/Features/Api/Services/AudibleServiceTests.cs | Adds tests verifying locale headers are sent for search + single/batch product lookups. |
| tests/Features/Api/Controllers/SearchControllerUnifiedTests.cs | Adds coverage for configured default region fallback and region/language threading into metadata calls + links. |
| tests/Features/Api/Controllers/LibraryController_AddToLibraryTests.cs | Verifies ASIN identifier region is persisted when adding to library. |
| listenarr.domain/Models/AudibleBookMetadata.cs | Adds Region to metadata payload model. |
| listenarr.application/Search/SearchService.cs | Passes region/language into ASIN search handler from intelligent search. |
| listenarr.application/Search/MetadataConverters.cs | Propagates region into metadata and builds region-aware Amazon/Audible product URLs. |
| listenarr.application/Search/AsinSearchHandler.cs | Uses requested region for metadata lookups and emits region-aware source links for ASIN searches. |
| listenarr.application/Metadata/AudibleService.cs | Enables locale headers for product endpoints and emits Audible (not Amazon) product link for ASIN direct lookups. |
| listenarr.application/Audiobooks/LibraryAddService.cs | Preserves ASIN region when backfilling imported identifiers during add-to-library. |
| listenarr.api/Controllers/SearchController.cs | Resolves missing regions from configured defaults, threads language into ASIN lookup, and normalizes Audible links to regional domains. |
| listenarr.api/Controllers/LibraryController.cs | Preserves ASIN region when syncing/backfilling imported identifiers. |
| fe/vite.config.ts | Cleans up config structure/formatting and limits esbuild “drop” config to production. |
| fe/src/views/library/AudiobookDetailView.vue | Builds Audible links using ASIN identifier region (when available). |
| fe/src/views/content/AddNewView.vue | Adds region selectors, defaults language from selected region, and uses regional Audible links throughout results + add flows. |
| fe/src/utils/languageMapping.ts | Adds helper to derive primary preferred language from a region. |
| fe/src/types/index.ts | Adds region to AudibleBookMetadata type. |
| fe/src/components/domain/audiobook/AudiobookModal.vue | Uses region-aware Audible product/source URL builder. |
| fe/src/components/domain/audiobook/AudiobookDetailsModal.vue | Uses region-aware Audible product/source URL builder. |
| fe/src/components/domain/audiobook/AddLibraryModal.vue | Preserves region in metadata payload and uses it for Audible metadata lookup + links. |
| fe/src/tests/test-setup.ts | Reworks localStorage polyfill to avoid Node localStorage warnings by defining test storage directly. |
| fe/src/tests/languageMapping.spec.ts | Adds tests for region→primary-language mapping helper. |
| fe/src/tests/AddNewView.spec.ts | Updates/adds tests for region selector UI, language defaulting, and regional Audible links in results. |
| fe/src/tests/AddLibraryModal.editableMetadata.spec.ts | Ensures region is passed to Audible metadata lookup and preserved in metadata updates. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 446a8a6f64
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Introduce region-aware Audible/Amazon product URLs and search region handling across frontend and backend. Frontend: add region select UI, persist/derive preferred language from region, thread region through search results and metadata, use buildAudibleProductUrl util, and add region to Audible metadata types. Backend: normalize Audible/Amazon domains, build product links using region, treat Audible URLs/hosts robustly, and include locale headers for Audible API calls. Also propagate region into ASIN searches and metadata converters. Tests were updated/added to reflect region-specific behavior and URL generation.
Make SearchController's region parameter nullable and resolve it via ResolveSearchRegionAsync, then use the resolved region when building the Audible sourceUrl. Replace AudibleService's hardcoded region-to-URL switch with MarketDomainResolver.GetAudibleDomain and add the necessary using. Centralizes region/domain logic and ensures consistent Audible base URLs.
Introduce caching and normalization for search results, add test builders and update docs. - SearchController / SettingsController: accept optional IMemoryCache, cache resolved default search region for 60s and remove cache when settings are saved. - Extract NormalizeMetadataSearchResultImagesAsync to centralize image normalization/caching (serve local /api images when possible) and replace duplicated code paths. - Frontend AddNewView: add region field to TitleSearchResult, extract normalizeResultRegionAndProductUrl helper, and add small test interaction (language select) in AddNewView.spec.ts. - Application: MarketDomainResolver now uses a single dictionary of markets; AsinSearchHandler signature allows nullable region. - Tests: add MetadataSearchResultBuilder and refactor SearchControllerUnifiedTests to use BaseTests/DI helpers; add new tests verifying default region fallbacks and regional sourceUrl behavior. - Docs: extend .github guidance files with pre-commit/pre-push rules, layering and async conventions, backend test conventions, and formatting quick-fix steps. These changes reduce duplication, improve regional URL handling, enable short-lived caching of default region, and add test helpers + docs to standardize test patterns.
Introduce reusable test builders (AudibleBookResponse, AudibleSearchResponse, AudibleSearchResult, SeriesLookupItem) and extend ApplicationSettingsBuilder. Refactor Listenarr.Application.Search to centralize Audible->AudibleBookResponse mapping (ToAudibleBookResponse) and ensure Region is populated. Update Listenarr.Api.SearchController to determine metadata source base URLs (Amazon vs Audible), move image normalization into NormalizeMetadataSearchResultImagesAsync and add safe background caching with logged failures. Update many tests to use the new builders and add SearchService integration tests. Frontend: ensure Amazon product links include region and add a unit test for Amazon metadata badge. Update repository docs (.github) to clarify formatting, layering and backend test conventions.
446a8a6 to
8e75aeb
Compare
clearAdvancedSearch now checks applicationSettings.defaultSearchLanguage and uses it (after normalizePreferredSearchLanguage) when present; only if no saved default exists does it fall back to the region primary via getPrimaryPreferredSearchLanguageForRegion(searchLanguage.value). This mirrors the onMounted behavior and preserves existing reset logic for errors and paging.
Summary
Fix Audible region handling so Add New/search uses the configured or ad-hoc region consistently, requests regional metadata, and emits regional Audible/Amazon links.
Fixes #530
Fixes #526
Changes
Added
Changed
SearchControllerrequest regions fromApplicationSettings.DefaultSearchRegionwhile preserving explicit ad-hoc request regions.Fixed
.comdomains.Testing
dotnet test Listenarr\listenarr.slnx --filter "FullyQualifiedName~SearchControllerUnifiedTests|FullyQualifiedName~AudibleServiceTests|FullyQualifiedName~SearchServiceFixesTests|FullyQualifiedName~LibraryController_AddToLibraryTests"npm run type-checknpm run test:unit -- --run src\__tests__\AddNewView.spec.ts src\__tests__\languageMapping.spec.ts src\__tests__\AddLibraryModal.editableMetadata.spec.ts.husky/pre-commitgit push -u origin bugfix/audible-regionhook: version sync, backend format, frontend type-check, full frontend tests (71 passed | 1 skipped,364 passed)Notes
NU1902warning.