mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
feat: sort mime types by count in statistics menu
This commit is contained in:
parent
8623687b42
commit
686875099f
@ -179,6 +179,9 @@ self.getUploadsStats = async db => {
|
||||
}
|
||||
}
|
||||
|
||||
// Mime types container
|
||||
const types = {}
|
||||
|
||||
for (const upload of uploads) {
|
||||
if (self.imageExtsRegex.test(upload.name)) {
|
||||
stats.Images.value++
|
||||
@ -196,13 +199,23 @@ self.getUploadsStats = async db => {
|
||||
|
||||
stats['Size in DB'].value += parseInt(upload.size)
|
||||
|
||||
if (stats['Mime Types'].value[upload.type] === undefined) {
|
||||
stats['Mime Types'].value[upload.type] = 0
|
||||
if (types[upload.type] === undefined) {
|
||||
types[upload.type] = 0
|
||||
}
|
||||
|
||||
stats['Mime Types'].value[upload.type]++
|
||||
types[upload.type]++
|
||||
}
|
||||
|
||||
// Sort mime types by count, and alphabetical ordering of the types
|
||||
stats['Mime Types'].value = Object.keys(types)
|
||||
.sort((a, b) => {
|
||||
return types[b] - types[a] || a.localeCompare(b)
|
||||
})
|
||||
.reduce((acc, type) => {
|
||||
acc[type] = types[type]
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user