mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
Propagate and use customSearchTerms for ebooks
Persist and apply customSearchTerms across ebook workflows and searches. Updated admin search-terms PATCH to enqueue addSearchEbookJob for ebook requests. Included customSearchTerms when creating ebook request records in audiobooks/[asin]/fetch-ebook, audiobooks/[asin]/select-ebook and requests/[id]/fetch-ebook. Reworked requests/[id]/select-ebook to handle being passed either an audiobook or ebook request (resolve parent audiobook, reuse existing ebook request if present) and to propagate parent.customSearchTerms when creating new ebook requests. Modified search-ebook.processor to read customSearchTerms from the request record, use it as the effective search title (with logging), and pass the modified audiobook title into Anna's Archive and indexer searches so custom terms are honored.
This commit is contained in:
@@ -100,15 +100,21 @@ export async function PATCH(
|
||||
},
|
||||
});
|
||||
|
||||
// Queue search job
|
||||
// Queue search job based on request type
|
||||
const { getJobQueueService } = await import('@/lib/services/job-queue.service');
|
||||
const jobQueue = getJobQueueService();
|
||||
await jobQueue.addSearchJob(id, {
|
||||
const audiobookData = {
|
||||
id: existingRequest.audiobook.id,
|
||||
title: existingRequest.audiobook.title,
|
||||
author: existingRequest.audiobook.author,
|
||||
asin: existingRequest.audiobook.audibleAsin || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
if (existingRequest.type === 'ebook') {
|
||||
await jobQueue.addSearchEbookJob(id, audiobookData);
|
||||
} else {
|
||||
await jobQueue.addSearchJob(id, audiobookData);
|
||||
}
|
||||
|
||||
searchTriggered = true;
|
||||
logger.info(`Search triggered for request ${id} with custom terms`, { requestId: id });
|
||||
|
||||
@@ -260,6 +260,7 @@ export async function POST(
|
||||
parentRequestId: availableRequest?.id || null, // Link to parent if exists
|
||||
status: 'awaiting_approval',
|
||||
progress: 0,
|
||||
customSearchTerms: availableRequest?.customSearchTerms || null,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -292,6 +293,7 @@ export async function POST(
|
||||
parentRequestId: availableRequest?.id || null,
|
||||
status: 'pending',
|
||||
progress: 0,
|
||||
customSearchTerms: availableRequest?.customSearchTerms || null,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -252,6 +252,7 @@ export async function POST(
|
||||
status: 'awaiting_approval',
|
||||
progress: 0,
|
||||
selectedTorrent: selectedEbook as any,
|
||||
customSearchTerms: availableRequest?.customSearchTerms || null,
|
||||
},
|
||||
});
|
||||
logger.info(`Created ebook request ${ebookRequest.id}, awaiting approval`);
|
||||
@@ -296,6 +297,7 @@ export async function POST(
|
||||
parentRequestId: availableRequest?.id || null,
|
||||
status: 'searching',
|
||||
progress: 0,
|
||||
customSearchTerms: availableRequest?.customSearchTerms || null,
|
||||
},
|
||||
});
|
||||
logger.info(`Created new ebook request ${ebookRequest.id}`);
|
||||
|
||||
@@ -123,6 +123,7 @@ export async function POST(
|
||||
parentRequestId,
|
||||
status: 'pending',
|
||||
progress: 0,
|
||||
customSearchTerms: parentRequest.customSearchTerms,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -52,17 +52,32 @@ export async function POST(
|
||||
return NextResponse.json({ error: 'Ebook source not specified' }, { status: 400 });
|
||||
}
|
||||
|
||||
// Get the parent audiobook request
|
||||
const parentRequest = await prisma.request.findUnique({
|
||||
// Get the request - could be an audiobook request or an existing ebook request
|
||||
const foundRequest = await prisma.request.findUnique({
|
||||
where: { id: parentRequestId },
|
||||
include: { audiobook: true },
|
||||
});
|
||||
|
||||
if (!parentRequest) {
|
||||
if (!foundRequest) {
|
||||
return NextResponse.json({ error: 'Request not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (parentRequest.type !== 'audiobook') {
|
||||
// If this is an ebook request, find the parent audiobook request
|
||||
let parentRequest;
|
||||
if (foundRequest.type === 'ebook') {
|
||||
if (!foundRequest.parentRequestId) {
|
||||
return NextResponse.json({ error: 'Ebook request has no parent audiobook request' }, { status: 400 });
|
||||
}
|
||||
parentRequest = await prisma.request.findUnique({
|
||||
where: { id: foundRequest.parentRequestId },
|
||||
include: { audiobook: true },
|
||||
});
|
||||
if (!parentRequest) {
|
||||
return NextResponse.json({ error: 'Parent audiobook request not found' }, { status: 404 });
|
||||
}
|
||||
} else if (foundRequest.type === 'audiobook') {
|
||||
parentRequest = foundRequest;
|
||||
} else {
|
||||
return NextResponse.json({ error: 'Can only select ebooks for audiobook requests' }, { status: 400 });
|
||||
}
|
||||
|
||||
@@ -74,13 +89,16 @@ export async function POST(
|
||||
}
|
||||
|
||||
// Check for existing ebook request
|
||||
let ebookRequest = await prisma.request.findFirst({
|
||||
where: {
|
||||
parentRequestId,
|
||||
type: 'ebook',
|
||||
deletedAt: null,
|
||||
},
|
||||
});
|
||||
// If we were given an ebook request ID directly, use that; otherwise search by parent
|
||||
let ebookRequest = foundRequest.type === 'ebook'
|
||||
? foundRequest
|
||||
: await prisma.request.findFirst({
|
||||
where: {
|
||||
parentRequestId: parentRequest.id,
|
||||
type: 'ebook',
|
||||
deletedAt: null,
|
||||
},
|
||||
});
|
||||
|
||||
if (ebookRequest && !['failed', 'awaiting_search', 'pending'].includes(ebookRequest.status)) {
|
||||
return NextResponse.json({
|
||||
@@ -109,9 +127,10 @@ export async function POST(
|
||||
userId: parentRequest.userId,
|
||||
audiobookId: parentRequest.audiobookId,
|
||||
type: 'ebook',
|
||||
parentRequestId,
|
||||
parentRequestId: parentRequest.id,
|
||||
status: 'searching',
|
||||
progress: 0,
|
||||
customSearchTerms: parentRequest.customSearchTerms,
|
||||
},
|
||||
});
|
||||
logger.info(`Created new ebook request ${ebookRequest.id}`);
|
||||
|
||||
Reference in New Issue
Block a user