mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-05 22:48:17 +08:00
⚙️ Fix show categories data
This commit is contained in:
parent
8a895cbb32
commit
d43c572311
@ -107,21 +107,23 @@ app.get('/categories', async (c) => {
|
||||
return c.json({ error: 'Too many request' }, 429);
|
||||
}
|
||||
|
||||
const categories = fullRouteSvgsData.reduce((acc, svg) => {
|
||||
const categoryTotals: Record<string, number> = {};
|
||||
|
||||
fullRouteSvgsData.forEach((svg) => {
|
||||
if (typeof svg.category === 'string') {
|
||||
if (!acc.includes(svg.category)) {
|
||||
acc.push(svg.category);
|
||||
}
|
||||
}
|
||||
if (Array.isArray(svg.category)) {
|
||||
categoryTotals[svg.category] = (categoryTotals[svg.category] || 0) + 1;
|
||||
} else if (Array.isArray(svg.category)) {
|
||||
svg.category.forEach((category) => {
|
||||
if (!acc.includes(category)) {
|
||||
acc.push(category);
|
||||
}
|
||||
categoryTotals[category] = (categoryTotals[category] || 0) + 1;
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
}, [] as string[]);
|
||||
});
|
||||
|
||||
const categories = Object.entries(categoryTotals).map(([category, total]) => ({
|
||||
category,
|
||||
total
|
||||
}));
|
||||
|
||||
return c.json(categories);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user