diff --git a/wrolpi/files/lib.py b/wrolpi/files/lib.py index 4d219fed..77ce6858 100644 --- a/wrolpi/files/lib.py +++ b/wrolpi/files/lib.py @@ -627,16 +627,17 @@ def get_file_statistics(): curs.execute(''' SELECT COUNT(path) AS "total_count", - COUNT(path) FILTER (WHERE file.mimetype LIKE 'video/%') AS "video_count", COUNT(path) FILTER (WHERE file.mimetype = 'application/pdf') AS "pdf_count", - COUNT(path) FILTER (WHERE file.mimetype LIKE 'image/%' AND file.associated = FALSE) AS "image_count", COUNT(path) FILTER (WHERE file.mimetype = 'application/zip') AS "zip_count", + COUNT(path) FILTER (WHERE file.mimetype LIKE 'video/%') AS "video_count", + COUNT(path) FILTER (WHERE file.mimetype LIKE 'image/%' AND file.associated = FALSE) AS "image_count", COUNT(path) FILTER (WHERE file.mimetype LIKE 'audio/%' AND file.associated = FALSE) AS "audio_count", SUM(size)::BIGINT AS "total_size" FROM file ''') statistics = dict(curs.fetchall()[0]) + statistics['total_size'] = statistics['total_size'] or 0 curs.execute('SELECT COUNT(*) FROM archive') statistics['archive_count'] = curs.fetchall()[0][0] diff --git a/wrolpi/files/test/test_api.py b/wrolpi/files/test/test_api.py index 682c1988..c82318a7 100644 --- a/wrolpi/files/test/test_api.py +++ b/wrolpi/files/test/test_api.py @@ -251,6 +251,7 @@ def test_file_statistics(test_session, test_client, example_pdf, example_mobi, e assert response.status_code == HTTPStatus.OK assert response.json['file_statistics'] == { 'archive_count': 0, + 'total_size': 0, 'audio_count': 0, 'ebook_count': 0, 'image_count': 0, @@ -264,7 +265,9 @@ def test_file_statistics(test_session, test_client, example_pdf, example_mobi, e request, response = test_client.get('/api/statistics') assert response.status_code == HTTPStatus.OK - assert response.json['file_statistics'] == { + stats = response.json['file_statistics'] + stats.pop('total_size') + assert stats == { 'archive_count': 0, 'audio_count': 0, 'ebook_count': 2,