fix: library stats showing 0KB due to incorrect fileSizeKb field path (#1436)

Co-authored-by: James Ward <james@notjam.es>
This commit is contained in:
IvyWooo
2026-06-09 18:37:05 -04:00
committed by GitHub
co-authored by James Ward
parent d1298afc45
commit f3dacb99b2
2 changed files with 62 additions and 1 deletions
@@ -94,4 +94,65 @@ describe('LibrariesSummaryService', () => {
});
expect(service.formattedSize()).toBe('1.00 GB');
});
it('uses primary file size when the book does not expose a top-level file size', () => {
books.set([
{
id: 1,
libraryId: 1,
libraryName: 'Alpha',
primaryFile: {
bookId: 1,
fileSizeKb: 2048,
},
metadata: {
bookId: 1,
authors: ['Alice'],
},
} as Book,
]);
const service = TestBed.inject(LibrariesSummaryService);
expect(service.booksSummary()).toEqual({
totalBooks: 1,
totalSizeKb: 2048,
totalAuthors: 1,
totalSeries: 0,
totalPublishers: 0,
});
expect(service.formattedSize()).toBe('2.00 MB');
});
it('prioritizes top-level file size when the book has a primary file size', () => {
books.set([
{
id: 1,
libraryId: 1,
libraryName: 'Alpha',
primaryFile: {
bookId: 1,
fileSizeKb: 2048,
},
fileSizeKb: 4096,
metadata: {
bookId: 1,
authors: ['Alice'],
},
} as Book,
]);
const service = TestBed.inject(LibrariesSummaryService);
expect(service.booksSummary()).toEqual({
totalBooks: 1,
totalSizeKb: 4096,
totalAuthors: 1,
totalSeries: 0,
totalPublishers: 0,
});
expect(service.formattedSize()).toBe('4.00 MB');
});
});
@@ -29,7 +29,7 @@ export class LibrariesSummaryService {
: books;
const totalBooks = filteredBooks.length;
const totalSizeKb = filteredBooks.reduce((sum, book) => sum + (book.fileSizeKb || 0), 0);
const totalSizeKb = filteredBooks.reduce((sum, book) => sum + (book.fileSizeKb ?? book.primaryFile?.fileSizeKb ?? 0), 0);
const authorSet = new Set<string>();
const seriesSet = new Set<string>();