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
@@ -256,9 +256,11 @@ describe('processOrganizeFiles', () => {
data: expect.objectContaining({ status: 'awaiting_import' }),
})
);
// Auto-block must NOT fire on a retry — only on the terminal warn transition.
expect(prismaMock.blockedRelease.upsert).not.toHaveBeenCalled();
});
it('marks request as warn when max retries exceeded and notifies user', async () => {
it('marks request as warn when max retries exceeded, auto-blocks the release, and notifies user', async () => {
prismaMock.request.update.mockResolvedValue({});
prismaMock.audiobook.findUnique.mockResolvedValue({
id: 'a6',
@@ -285,6 +287,20 @@ describe('processOrganizeFiles', () => {
audiobook: { title: 'Book', author: 'Author' },
user: { plexUsername: 'user' },
});
prismaMock.downloadHistory.findFirst.mockResolvedValue({
id: 'dh-6',
torrentName: 'Book by Author [M4B]',
torrentHash: 'hash-6',
nzbId: null,
indexerName: 'TestIndexer',
indexerId: 7,
});
prismaMock.blockedRelease.upsert.mockResolvedValue({
id: 'block-6',
releaseName: 'Book by Author [M4B]',
releaseKey: 'book by author [m4b]',
createdAt: new Date(),
});
configMock.get.mockResolvedValue(null);
const { processOrganizeFiles } = await import('@/lib/processors/organize-files.processor');
@@ -309,6 +325,23 @@ describe('processOrganizeFiles', () => {
'user',
expect.stringContaining('Max retries')
);
// Terminal warn writes a single blocklist row keyed on the selected download.
expect(prismaMock.blockedRelease.upsert).toHaveBeenCalledWith(
expect.objectContaining({
where: { requestId_releaseKey: { requestId: 'req-6', releaseKey: 'book by author [m4b]' } },
create: expect.objectContaining({
requestId: 'req-6',
releaseName: 'Book by Author [M4B]',
releaseKey: 'book by author [m4b]',
releaseHash: 'hash-6',
indexerName: 'TestIndexer',
indexerId: 7,
source: 'organize_fail',
reason: 'No audiobook files found',
downloadHistoryId: 'dh-6',
}),
})
);
});
it('marks request failed for non-retryable errors and notifies user', async () => {
@@ -357,6 +390,8 @@ describe('processOrganizeFiles', () => {
'user',
expect.stringContaining('File organization failed')
);
// Non-retryable failures do not auto-block — only terminal warn does.
expect(prismaMock.blockedRelease.upsert).not.toHaveBeenCalled();
});
it('queues retry when organizer returns EPERM copy failure', async () => {