Skip to content

Commit ee500b9

Browse files
authored
πŸ› fix: force convert string to array, may fix #54
1 parent 7fa4d22 commit ee500b9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

β€Žsrc/app/api/search/route.tsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getPluginSettingsFromRequest,
66
} from '@lobehub/chat-plugin-sdk';
77
import { SearchParameters, Settings } from '@/type';
8+
import { normalizeCategories } from '@/utils/normalizeCategories';
89

910
export async function POST(req: NextRequest) {
1011
try {
@@ -29,7 +30,7 @@ export async function POST(req: NextRequest) {
2930
const { categories, q, time_range } = (await req.json()) as SearchParameters;
3031

3132
const searchParameters: SearchParameters = {
32-
...(categories ? { categories: categories.join(',') } : {}),
33+
...(categories ? { categories: normalizeCategories(categories) } : {}),
3334
format: 'json',
3435
q,
3536
...(time_range ? { time_range } : {}),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const normalizeCategories = (categories?: string | string[]): string | undefined => {
2+
if (!categories) return undefined;
3+
if (typeof categories === 'string') {
4+
try {
5+
const parsed = JSON.parse(categories);
6+
if (Array.isArray(parsed)) return parsed.join(',');
7+
} catch {
8+
return categories;
9+
}
10+
}
11+
return Array.isArray(categories) ? categories.join(',') : undefined;
12+
};

0 commit comments

Comments
Β (0)