mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-31 01:01:11 +08:00
fix(api/category): category api return data
This commit is contained in:
+4
-12
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user