Merge pull request #202 from xFlawless11x/feature/cancel-pending-approval

feat: allow cancellation of pending-approval requests
This commit is contained in:
kikootwo
2026-05-15 06:46:33 -04:00
committed by GitHub
5 changed files with 115 additions and 7 deletions
@@ -66,7 +66,7 @@ export function RequestActionsDropdown({
const canSearch = ['pending', 'failed', 'awaiting_search'].includes(request.status);
const canAdjustSearchTerms = ['pending', 'failed', 'awaiting_search', 'searching'].includes(request.status);
const canRetryDownload = request.status === 'failed' && (request.downloadAttempts ?? 0) > 0 && !!onRetryDownload;
const canCancel = ['pending', 'searching', 'downloading', 'awaiting_search'].includes(request.status);
const canCancel = ['pending', 'searching', 'downloading', 'awaiting_search', 'awaiting_approval'].includes(request.status);
const canDelete = true; // Admins can always delete
// View Source: For ebooks, extract MD5 from slow download URL and link to Anna's Archive
@@ -159,7 +159,11 @@ export function RequestActionsDropdown({
const handleCancel = async () => {
setIsOpen(false);
if (window.confirm(`Are you sure you want to cancel the request for "${request.title}"?`)) {
const statusNote = request.status === 'awaiting_approval'
? ' It is pending admin approval and will be withdrawn.'
: ' It has already been approved and is actively being processed/monitored.';
const message = `Are you sure you want to cancel this request?${statusNote}`;
if (window.confirm(message)) {
try {
await onCancel(request.requestId);
} catch (error) {
+32 -1
View File
@@ -112,6 +112,10 @@ export async function PATCH(
id,
deletedAt: null, // Only allow updates to active requests
},
include: {
audiobook: true,
user: { select: { plexUsername: true } },
},
});
if (!requestRecord) {
@@ -130,18 +134,45 @@ export async function PATCH(
}
if (action === 'cancel') {
// Cancel the request
const cancellableStatuses = ['pending', 'searching', 'downloading', 'awaiting_search', 'awaiting_approval'];
if (!cancellableStatuses.includes(requestRecord.status)) {
return NextResponse.json(
{
error: 'ValidationError',
message: `Cannot cancel request with status: ${requestRecord.status}`,
},
{ status: 400 }
);
}
const isAwaitingApproval = requestRecord.status === 'awaiting_approval';
const updated = await prisma.request.update({
where: { id },
data: {
status: 'cancelled',
updatedAt: new Date(),
...(isAwaitingApproval && { selectedTorrent: null as any }),
},
include: {
audiobook: true,
},
});
try {
const { getJobQueueService } = await import('@/lib/services/job-queue.service');
const jobQueue = getJobQueueService();
await jobQueue.addNotificationJob(
'request_cancelled',
updated.id,
updated.audiobook.title,
updated.audiobook.author,
requestRecord.user.plexUsername || 'Unknown User'
);
} catch (error) {
logger.error('Failed to queue cancellation notification', { error });
}
return NextResponse.json({
success: true,
request: updated,