File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 5
5
getPluginSettingsFromRequest ,
6
6
} from '@lobehub/chat-plugin-sdk' ;
7
7
import { SearchParameters , Settings } from '@/type' ;
8
+ import { normalizeCategories } from '@/utils/normalizeCategories' ;
8
9
9
10
export async function POST ( req : NextRequest ) {
10
11
try {
@@ -29,7 +30,7 @@ export async function POST(req: NextRequest) {
29
30
const { categories, q, time_range } = ( await req . json ( ) ) as SearchParameters ;
30
31
31
32
const searchParameters : SearchParameters = {
32
- ...( categories ? { categories : categories . join ( ',' ) } : { } ) ,
33
+ ...( categories ? { categories : normalizeCategories ( categories ) } : { } ) ,
33
34
format : 'json' ,
34
35
q,
35
36
...( time_range ? { time_range } : { } ) ,
Original file line number Diff line number Diff line change
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
+ } ;
You canβt perform that action at this time.
0 commit comments