mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-09-10 17:58:02 +02:00
updated controller
This commit is contained in:
parent
39d40d5ef3
commit
793ef0e9ec
@ -48,7 +48,7 @@ class LibraryController {
|
|||||||
async allStats(req, res) {
|
async allStats(req, res) {
|
||||||
try {
|
try {
|
||||||
const allStats = [];
|
const allStats = [];
|
||||||
const combinedStats = { sizes: {}, top: {} }; // Clear structure for combined stats
|
const combinedStats = {};
|
||||||
let libraries = await Database.libraryModel.getAllWithFolders();
|
let libraries = await Database.libraryModel.getAllWithFolders();
|
||||||
const librariesAccessible = req.user.permissions?.librariesAccessible || [];
|
const librariesAccessible = req.user.permissions?.librariesAccessible || [];
|
||||||
|
|
||||||
@ -74,22 +74,25 @@ class LibraryController {
|
|||||||
combinedStats[key] = (combinedStats[key] || 0) + value;
|
combinedStats[key] = (combinedStats[key] || 0) + value;
|
||||||
} else if (typeof value === "object") {
|
} else if (typeof value === "object") {
|
||||||
for (const [subKey, subValue] of Object.entries(value)) {
|
for (const [subKey, subValue] of Object.entries(value)) {
|
||||||
if (subValue['size'] !== undefined) {
|
for (const keyType of ['size', 'count', 'duration']) {
|
||||||
if (combinedStats[key] === undefined) combinedStats[key] = [];
|
if (subValue[keyType] !== undefined) {
|
||||||
// Insert the current value into the combined stats if its size is bigger than the ten biggest sizes
|
if (combinedStats[key] === undefined) combinedStats[key] = [];
|
||||||
console.log(subValue['size'])
|
// Insert the current value into the combined stats if its size is bigger than the ten biggest sizes
|
||||||
if (Object.entries(combinedStats[key]).length < 10) {
|
if (Object.entries(combinedStats[key]).length < 10) {
|
||||||
combinedStats[key].push(subValue);
|
|
||||||
// Sort the array of sizes
|
|
||||||
combinedStats[key].sort((a, b) => b["size"] - a["size"]);
|
|
||||||
} else {
|
|
||||||
if (subValue['size'] > combinedStats[key][9]['size']) {
|
|
||||||
combinedStats[key].pop();
|
|
||||||
combinedStats[key].push(subValue);
|
combinedStats[key].push(subValue);
|
||||||
combinedStats[key].sort((a, b) => b["size"] - a["size"]);
|
// Sort the array of sizes
|
||||||
|
combinedStats[key].sort((a, b) => b[keyType] - a[keyType]);
|
||||||
|
} else {
|
||||||
|
if (subValue[keyType] > combinedStats[key][9][keyType]) {
|
||||||
|
combinedStats[key].pop();
|
||||||
|
combinedStats[key].push(subValue);
|
||||||
|
combinedStats[key].sort((a, b) => b[keyType] - a[keyType]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user