MCPcopy Create free account
hub / github.com/code100x/cms / GET

Function GET

src/app/api/search/route.ts:24–61  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

22};
23
24export async function GET(request: NextRequest) {
25 const { searchParams } = new URL(request.url);
26 const searchQuery = searchParams.get('q');
27
28 if (searchQuery && searchQuery.length > 2) {
29 const value: TSearchedVideos[] = await cache.get(
30 'getAllVideosForSearch',
31 [],
32 );
33
34 if (value) {
35 return NextResponse.json(fuzzySearch(value, searchQuery));
36 }
37
38 const allVideos = await db.content.findMany({
39 where: {
40 type: 'video',
41 hidden: false,
42 },
43 select: {
44 id: true,
45 parentId: true,
46 title: true,
47 parent: {
48 select: {
49 courses: true,
50 },
51 },
52 },
53 });
54
55 cache.set('getAllVideosForSearch', [], allVideos, 24 * 60 * 60);
56
57 return NextResponse.json(fuzzySearch(allVideos, searchQuery));
58 }
59
60 return NextResponse.json({}, { status: 400 });
61}

Callers

nothing calls this directly

Calls 3

fuzzySearchFunction · 0.70
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected