Implement file hash-based library matching and remove fuzzy ASIN matching

Adds file hash-based matching for Audiobookshelf library items to ensure 100% accurate ASIN assignment for RMAB-organized content. Removes fuzzy matching from library availability checks, making all matching ASIN-only to eliminate false positives and race conditions. Updates database schema, processors, and matcher utilities; adds new tests and documentation for the new matching strategy. Removes obsolete scripts, Dockerfile, and related tests; updates docker-compose for test environments.
This commit is contained in:
kikootwo
2026-01-28 10:32:14 -05:00
parent 497849f427
commit a97979358f
111 changed files with 6571 additions and 1426 deletions
@@ -339,6 +339,55 @@ describe('processOrganizeFiles', () => {
expect.stringContaining('File organization failed')
);
});
it('generates and stores filesHash after successful organization', async () => {
prismaMock.request.update.mockResolvedValue({});
prismaMock.audiobook.findUnique.mockResolvedValue({
id: 'a-hash-1',
title: 'Book With Hash',
author: 'Author',
narrator: null,
coverArtUrl: null,
audibleAsin: 'ASIN-HASH',
});
organizerMock.organize.mockResolvedValue({
success: true,
targetPath: '/media/Author/Book',
filesMovedCount: 3,
errors: [],
audioFiles: [
'/media/Author/Book/Chapter 01.mp3',
'/media/Author/Book/Chapter 02.mp3',
'/media/Author/Book/Chapter 03.mp3',
],
});
prismaMock.audiobook.update.mockResolvedValue({});
prismaMock.request.update.mockResolvedValue({});
configMock.getBackendMode.mockResolvedValue('audiobookshelf');
configMock.get.mockResolvedValue('false');
const { processOrganizeFiles } = await import('@/lib/processors/organize-files.processor');
const result = await processOrganizeFiles({
requestId: 'req-hash-1',
audiobookId: 'a-hash-1',
downloadPath: '/downloads/book',
jobId: 'job-hash-1',
});
expect(result.success).toBe(true);
// Verify filesHash was included in the audiobook update
expect(prismaMock.audiobook.update).toHaveBeenCalledWith(
expect.objectContaining({
where: { id: 'a-hash-1' },
data: expect.objectContaining({
filePath: '/media/Author/Book',
filesHash: expect.stringMatching(/^[a-f0-9]{64}$/), // SHA256 hash format
status: 'completed',
}),
})
);
});
});