From 88ba73ba9d5d0cac4d5308f5930d4449c9a30bde Mon Sep 17 00:00:00 2001 From: Yiwei Ho Date: Sun, 14 Apr 2024 08:39:32 +0800 Subject: [PATCH] fix: filter SVGs by category doesn't handle multiple categories's SVGs --- src/routes/api/svgs/+server.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/routes/api/svgs/+server.ts b/src/routes/api/svgs/+server.ts index 297ff64..b49ed36 100644 --- a/src/routes/api/svgs/+server.ts +++ b/src/routes/api/svgs/+server.ts @@ -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'; @@ -58,7 +59,17 @@ export const GET = async ({ url, request }: RequestEvent) => { if (category) { const categorySvgs = fullRouteSvgsData.filter((svg) => { - return svg.category === category.charAt(0).toUpperCase() + category.slice(1); + const targetCategory = 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: