mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
Fix bulk import: group tagless files by folder, use folder name as search fallback
This commit is contained in:
@@ -159,7 +159,29 @@ export async function POST(request: NextRequest) {
|
||||
let hasActiveRequest = false;
|
||||
|
||||
try {
|
||||
const searchResult = await audibleService.search(book.searchTerm);
|
||||
// If the scanner extracted an ASIN directly from the folder name,
|
||||
// try an exact ASIN lookup first — faster and more accurate than
|
||||
// a text search. Fall back to text search if it fails or returns
|
||||
// no result.
|
||||
let searchResult: Awaited<ReturnType<typeof audibleService.search>> | null = null;
|
||||
|
||||
if (book.extractedAsin) {
|
||||
try {
|
||||
const asinResult = await audibleService.search(book.extractedAsin);
|
||||
if (
|
||||
asinResult.results.length > 0 &&
|
||||
asinResult.results[0].asin === book.extractedAsin
|
||||
) {
|
||||
searchResult = asinResult;
|
||||
}
|
||||
} catch {
|
||||
/* ASIN lookup failed — fall through to text search */
|
||||
}
|
||||
}
|
||||
|
||||
if (!searchResult) {
|
||||
searchResult = await audibleService.search(book.searchTerm);
|
||||
}
|
||||
|
||||
if (searchResult.results.length > 0) {
|
||||
match = searchResult.results[0];
|
||||
@@ -208,6 +230,7 @@ export async function POST(request: NextRequest) {
|
||||
audioFileCount: book.audioFileCount,
|
||||
totalSizeBytes: book.totalSizeBytes,
|
||||
metadataSource: book.metadataSource,
|
||||
extractedAsin: book.extractedAsin,
|
||||
searchTerm: book.searchTerm,
|
||||
audioFiles: book.audioFiles,
|
||||
match: match
|
||||
|
||||
Reference in New Issue
Block a user