Add release blocklist feature

Introduce a per-request release blocklist to auto-block permanently failing releases and provide admin management. Changes include:

- Database: add BlockedRelease model (blocked_releases) to Prisma schema with unique (requestId, releaseKey) and indexes; documented in backend database docs.
- Service & utils: new blocklist.service, release-key and filter helpers for normalization and matching; processors updated to emit auto-blocks (monitor-download, organize-files, search processors, RSS).
- HTTP API: add admin endpoints GET/DELETE /api/admin/blocklist, DELETE /api/admin/blocklist/[id], and GET /api/admin/blocklist/by-request/[requestId].
- Admin UI: new /admin/blocklist page and numerous React components (toolbar, filters, table, rows, pagination, skeleton, chips, date picker) with URL-driven state hook and per-row unblock UX.
- Tests: add unit/integration tests for service, routes, utils, and updated processor tests.

The blocklist is idempotent (upsert), filters search results before ranking (interactive search shows badges only), and admin-only APIs require auth. This commit wires docs, API, DB, frontend and tests for the new feature.
This commit is contained in:
kikootwo
2026-05-18 12:15:51 -04:00
parent fb0445d95f
commit b1492fc32e
41 changed files with 4098 additions and 12 deletions
@@ -36,6 +36,8 @@ describe('processSearchIndexers', () => {
beforeEach(() => {
vi.clearAllMocks();
configMock.getAudibleRegion.mockResolvedValue('us');
// Default to empty blocklist so the filter is a no-op unless a test overrides.
prismaMock.blockedRelease.findMany.mockResolvedValue([]);
});
it('marks request awaiting_search when no results found', async () => {
@@ -124,6 +126,178 @@ describe('processSearchIndexers', () => {
})
);
});
it('filters out blocklisted releases by name (case-insensitive) before ranking', async () => {
configMock.get.mockImplementation(async (key: string) => {
if (key === 'prowlarr_indexers') {
return JSON.stringify([{ id: 1, name: 'Indexer', protocol: 'torrent', priority: 10, categories: [3030] }]);
}
if (key === 'indexer_flag_config') return JSON.stringify([]);
return null;
});
prowlarrMock.searchWithVariations.mockResolvedValue([
{
indexer: 'Indexer',
indexerId: 1,
title: 'BAD Release - Author',
size: 50 * 1024 * 1024,
seeders: 10,
publishDate: new Date(),
downloadUrl: 'magnet:?xt=urn:btih:bad',
guid: 'guid-bad',
format: 'M4B',
},
{
indexer: 'Indexer',
indexerId: 1,
title: 'Good Release - Author',
size: 50 * 1024 * 1024,
seeders: 20,
publishDate: new Date(),
downloadUrl: 'magnet:?xt=urn:btih:good',
guid: 'guid-good',
format: 'M4B',
},
]);
// Blocklist contains the bad release with lowercased key — must match case-insensitively.
prismaMock.blockedRelease.findMany.mockResolvedValue([
{ id: 'b1', releaseKey: 'bad release - author', releaseHash: null },
]);
prismaMock.request.update.mockResolvedValue({});
const { processSearchIndexers } = await import('@/lib/processors/search-indexers.processor');
const result = await processSearchIndexers({
requestId: 'req-filter-name',
audiobook: { id: 'a-filter', title: 'Good Release', author: 'Author' },
jobId: 'job-filter-name',
});
expect(result.success).toBe(true);
expect(jobQueueMock.addDownloadJob).toHaveBeenCalledTimes(1);
expect(jobQueueMock.addDownloadJob).toHaveBeenCalledWith(
'req-filter-name',
expect.objectContaining({ id: 'a-filter' }),
expect.objectContaining({ title: 'Good Release - Author' })
);
});
it('filters out blocklisted releases by infoHash even when title differs', async () => {
configMock.get.mockImplementation(async (key: string) => {
if (key === 'prowlarr_indexers') {
return JSON.stringify([{ id: 1, name: 'Indexer', protocol: 'torrent', priority: 10, categories: [3030] }]);
}
if (key === 'indexer_flag_config') return JSON.stringify([]);
return null;
});
prowlarrMock.searchWithVariations.mockResolvedValue([
{
indexer: 'Indexer',
indexerId: 1,
title: 'Some Other Title - Author',
size: 50 * 1024 * 1024,
seeders: 10,
publishDate: new Date(),
downloadUrl: 'magnet:?xt=urn:btih:abc',
guid: 'guid-hash-bad',
infoHash: 'abc123',
format: 'M4B',
},
{
indexer: 'Indexer',
indexerId: 1,
title: 'Good Release - Author',
size: 50 * 1024 * 1024,
seeders: 20,
publishDate: new Date(),
downloadUrl: 'magnet:?xt=urn:btih:def',
guid: 'guid-hash-good',
infoHash: 'def456',
format: 'M4B',
},
]);
prismaMock.blockedRelease.findMany.mockResolvedValue([
{ id: 'b2', releaseKey: 'unrelated key', releaseHash: 'abc123' },
]);
prismaMock.request.update.mockResolvedValue({});
const { processSearchIndexers } = await import('@/lib/processors/search-indexers.processor');
const result = await processSearchIndexers({
requestId: 'req-filter-hash',
audiobook: { id: 'a-filter-hash', title: 'Good Release', author: 'Author' },
jobId: 'job-filter-hash',
});
expect(result.success).toBe(true);
expect(jobQueueMock.addDownloadJob).toHaveBeenCalledWith(
'req-filter-hash',
expect.anything(),
expect.objectContaining({ title: 'Good Release - Author' })
);
});
it('uses blocklist-exhaustion message when every candidate is blocked', async () => {
configMock.get.mockImplementation(async (key: string) => {
if (key === 'prowlarr_indexers') {
return JSON.stringify([{ id: 1, name: 'Indexer', protocol: 'torrent', priority: 10, categories: [3030] }]);
}
if (key === 'indexer_flag_config') return JSON.stringify([]);
return null;
});
prowlarrMock.searchWithVariations.mockResolvedValue([
{
indexer: 'Indexer',
indexerId: 1,
title: 'Bad Release One',
size: 50 * 1024 * 1024,
seeders: 10,
publishDate: new Date(),
downloadUrl: 'magnet:?xt=urn:btih:1',
guid: 'g1',
format: 'M4B',
},
{
indexer: 'Indexer',
indexerId: 1,
title: 'Bad Release Two',
size: 50 * 1024 * 1024,
seeders: 5,
publishDate: new Date(),
downloadUrl: 'magnet:?xt=urn:btih:2',
guid: 'g2',
format: 'M4B',
},
]);
prismaMock.blockedRelease.findMany.mockResolvedValue([
{ id: 'b1', releaseKey: 'bad release one', releaseHash: null },
{ id: 'b2', releaseKey: 'bad release two', releaseHash: null },
]);
prismaMock.request.update.mockResolvedValue({});
const { processSearchIndexers } = await import('@/lib/processors/search-indexers.processor');
const result = await processSearchIndexers({
requestId: 'req-exhausted',
audiobook: { id: 'a-exhausted', title: 'Bad Release', author: 'Author' },
jobId: 'job-exhausted',
});
expect(result.success).toBe(false);
expect(result.message).toMatch(/No usable releases — 2 candidates tried, all blocked/);
expect(prismaMock.request.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
status: 'awaiting_search',
errorMessage: 'No usable releases — 2 candidates tried, all blocked',
}),
})
);
expect(jobQueueMock.addDownloadJob).not.toHaveBeenCalled();
});
});