mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-05 22:48:17 +08:00
Merge pull request #298 from 1weiho/main
Fix filter SVGs by category doesn't handle multiple categories's SVGs
This commit is contained in:
commit
212df3c4c4
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user