MCPcopy Create free account
hub / github.com/Fibi66/FeiControl / searchInFile

Function searchInFile

src/app/api/search/route.ts:19–44  ·  view source on GitHub ↗
(filePath: string, query: string)

Source from the content-addressed store, hash-verified

17}
18
19function searchInFile(filePath: string, query: string): SearchResult[] {
20 const results: SearchResult[] = [];
21 try {
22 const content = fs.readFileSync(filePath, 'utf-8');
23 const lines = content.split('\n');
24 const lowerQuery = query.toLowerCase();
25
26 lines.forEach((line, index) => {
27 if (line.toLowerCase().includes(lowerQuery)) {
28 const start = Math.max(0, index - 1);
29 const end = Math.min(lines.length, index + 2);
30 const snippet = lines.slice(start, end).join('\n');
31
32 results.push({
33 type: 'memory',
34 title: path.basename(filePath),
35 snippet: snippet.substring(0, 200),
36 path: filePath
37 });
38 }
39 });
40 } catch {
41 // Skip files that can't be read
42 }
43 return results;
44}
45
46export async function GET(request: Request) {
47 const { searchParams } = new URL(request.url);

Callers 1

GETFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected