Merge pull request #298 from 1weiho/main

Fix filter SVGs by category doesn't handle multiple categories's SVGs
This commit is contained in:
Pablo Hdez 2024-04-14 14:20:26 +01:00 committed by GitHub
commit 212df3c4c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import type { RequestEvent } from './$types';
import type { iSVG } from '@/types/svg';
import type { tCategory } from '@/types/categories';
import { error, json } from '@sveltejs/kit';
import { ratelimit } from '@/server/redis';
@ -57,8 +58,17 @@ export const GET = async ({ url, request }: RequestEvent) => {
const category = getCategoryParams;
if (category) {
const targetCategory = category.charAt(0).toUpperCase() + category.slice(1);
const categorySvgs = fullRouteSvgsData.filter((svg) => {
return svg.category === category.charAt(0).toUpperCase() + category.slice(1);
if (typeof svg.category === 'string') {
return svg.category === targetCategory;
}
if (Array.isArray(svg.category)) {
return svg.category.includes(targetCategory as tCategory);
}
return false;
});
// Error 400 | If category does not exist: