From 9dab97a4f7cea5bd973f19e6f83e0cbcb5cfe9ad Mon Sep 17 00:00:00 2001 From: Vito0912 <86927734+Vito0912@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:16:43 +0100 Subject: [PATCH] updated view --- client/components/stats/PreviewIcons.vue | 18 ++- client/pages/config/server-stats.vue | 159 +++++++++++++++++++++++ server/controllers/LibraryController.js | 75 ++++++----- 3 files changed, 220 insertions(+), 32 deletions(-) create mode 100644 client/pages/config/server-stats.vue diff --git a/client/components/stats/PreviewIcons.vue b/client/components/stats/PreviewIcons.vue index 7eea9d510..ca64e8af6 100644 --- a/client/components/stats/PreviewIcons.vue +++ b/client/components/stats/PreviewIcons.vue @@ -10,6 +10,14 @@ +
+ podcasts +
+

{{ $formatNumber(numAudioTracks) }}

+

Episodes

+
+
+
show_chart
@@ -36,7 +44,7 @@
-
+
audio_file

{{ $formatNumber(numAudioTracks) }}

@@ -52,18 +60,22 @@ export default { libraryStats: { type: Object, default: () => {} - } + }, + mediaType: null }, data() { return {} }, computed: { currentLibraryMediaType() { - return this.$store.getters['libraries/getCurrentLibraryMediaType'] + return this.mediaType || this.$store.getters['libraries/getCurrentLibraryMediaType'] }, isBookLibrary() { return this.currentLibraryMediaType === 'book' }, + isOverView(){ + return this.mediaType === 'overview' + }, user() { return this.$store.state.user.user }, diff --git a/client/pages/config/server-stats.vue b/client/pages/config/server-stats.vue new file mode 100644 index 000000000..9684c9bf5 --- /dev/null +++ b/client/pages/config/server-stats.vue @@ -0,0 +1,159 @@ + + + diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 0426bab87..5c37df724 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -48,7 +48,11 @@ class LibraryController { async allStats(req, res) { try { const allStats = []; - const combinedStats = {}; + const combinedStats = { + all: {}, + books: {}, + podcasts: {} + }; let libraries = await Database.libraryModel.getAllWithFolders(); const librariesAccessible = req.user.permissions?.librariesAccessible || []; @@ -63,41 +67,54 @@ class LibraryController { const libraryStats = await libraryHelpers.getLibraryStats(req); // Add this library's stats to the array of individual stats - allStats.push({ [library.id]: libraryStats }); + allStats.push({ + 'id': library.id, + 'name': library.name, + 'type': library.mediaType, + 'stats': libraryStats + }); - // Combine all stats - for (const [key, value] of Object.entries(libraryStats)) { - if (typeof value === "number") { - combinedStats[key] = (combinedStats[key] || 0) + value; - } else if (typeof value === "object") { - if (!combinedStats[key]) combinedStats[key] = []; + // Combine stats for all categories + const categories = ['all']; + if (library.mediaType === 'book') categories.push('books'); + if (library.mediaType === 'podcast') categories.push('podcasts'); - combinedStats[key].push(...Object.values(value)); + // Process each relevant category + categories.forEach(category => { + for (const [key, value] of Object.entries(libraryStats)) { + if (typeof value === "number") { + combinedStats[category][key] = (combinedStats[category][key] || 0) + value; + } else if (typeof value === "object") { + if (!combinedStats[category][key]) combinedStats[category][key] = []; + combinedStats[category][key].push(...Object.values(value)); + } + } + }); + } + + // Process arrays to keep top 10 entries for all categories + Object.keys(combinedStats).forEach(category => { + for (const key in combinedStats[category]) { + if (Array.isArray(combinedStats[category][key])) { + combinedStats[category][key] = combinedStats[category][key] + .sort((a, b) => { + const props = ['size', 'count', 'duration']; + for (const prop of props) { + if (a[prop] !== undefined && b[prop] !== undefined) { + return b[prop] - a[prop]; + } + } + return 0; + }) + .slice(0, 10); } } - } - - // Process arrays to keep top 10 entries based on 'size', 'count', or 'duration' - for (const key in combinedStats) { - if (Array.isArray(combinedStats[key])) { - combinedStats[key] = combinedStats[key] - .sort((a, b) => { - const props = ['size', 'count', 'duration']; - for (const prop of props) { - if (a[prop] !== undefined && b[prop] !== undefined) { - return b[prop] - a[prop]; - } - } - return 0; - }) - .slice(0, 10); - } - } + }); // Respond with the aggregated stats res.json({ - libraries: allStats, // Individual library stats - combined: combinedStats // Combined aggregated stats + libraries: allStats, + combined: combinedStats }); } catch (error) { res.status(500).json({ error: error.message });