fix(api/category): category api return data

This commit is contained in:
pseudoyu
2024-11-02 00:24:55 +07:00
parent afcea8f4ee
commit 6348c1ccec
+4 -12
View File
@@ -67,23 +67,15 @@ const handler: RouteHandler<typeof route> = (ctx) => {
// Get namespaces that exist in all requested categories
const commonNamespaces = Object.keys(categoryList[category] || {}).filter((namespace) => allCategories.every((cat) => categoryList[cat]?.[namespace]));
// Create result using the path category as key
let result = {
[category]: Object.fromEntries(commonNamespaces.map((namespace) => [namespace, categoryList[category][namespace]])),
};
// Create result directly from common namespaces
let result = Object.fromEntries(commonNamespaces.map((namespace) => [namespace, categoryList[category][namespace]]));
// Filter by language if provided
if (lang) {
result = Object.fromEntries(
Object.entries(result)
.map(([cat, namespaces]) => [cat, Object.fromEntries(Object.entries(namespaces).filter(([, value]) => value.lang === lang))])
.filter(([, namespaces]) => Object.keys(namespaces).length > 0)
);
result = Object.fromEntries(Object.entries(result).filter(([, value]) => value.lang === lang));
}
return ctx.json({
data: result,
});
return ctx.json(result);
};
export { route, handler };