fix(api): sort images count and types count

This commit is contained in:
diced 2021-09-06 15:22:36 -07:00
parent 606821a2c0
commit a06d5ffaed
No known key found for this signature in database
GPG key ID: 85AB64C74535D76E

View file

@ -43,21 +43,19 @@ async function handler(req: NextApiReq, res: NextApiRes) {
by: ['mimetype'], by: ['mimetype'],
_count: { _count: {
mimetype: true mimetype: true
} },
}); });
const types_count = []; const types_count = [];
for (let i = 0, L = typesCount.length; i !== L; ++i) { for (let i = 0, L = typesCount.length; i !== L; ++i) types_count.push({ mimetype: typesCount[i].mimetype, count: typesCount[i]._count.mimetype });
types_count.push({ mimetype: typesCount[i].mimetype, count: typesCount[i]._count.mimetype });
}
return res.json({ return res.json({
size: bytesToRead(size), size: bytesToRead(size),
size_num: size, size_num: size,
count, count,
count_by_user, count_by_user: count_by_user.sort((a,b) => b.count-a.count),
count_users, count_users,
views_count: (viewsCount[0]?._sum?.views ?? 0), views_count: (viewsCount[0]?._sum?.views ?? 0),
types_count types_count: types_count.sort((a,b) => b.count-a.count)
}); });
} }