From c7d509b7257c0be024015aeb43d57a56a4699cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Thu, 5 Mar 2026 00:58:10 +0000 Subject: [PATCH] scope file search to current directory Co-Authored-By: Claude Opus 4.6 --- src/servers/api/file-browser/router.ts | 4 +++- .../src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts | 2 +- src/workspaces/officerdev/src/hooks/useFilesAPI.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/servers/api/file-browser/router.ts b/src/servers/api/file-browser/router.ts index 75c13944..655e1a50 100644 --- a/src/servers/api/file-browser/router.ts +++ b/src/servers/api/file-browser/router.ts @@ -843,6 +843,8 @@ router.get('/search', async (ctx) => { const rootDir = getRootDir(user, ctx.req.query('root') ?? undefined); const query = (ctx.req.query('q') || '').trim().toLowerCase(); if (!query) throw errors.BAD_REQUEST('q is required'); + const searchPath = ctx.req.query('path') || ''; + const startDir = searchPath ? resolveUserPath(rootDir, searchPath) : rootDir; const MAX_RESULTS = 50; const results: { path: string; name: string; type: string; size: number; modifiedAt: number }[] = []; @@ -870,7 +872,7 @@ router.get('/search', async (ctx) => { } } - await walk(rootDir); + await walk(startDir); return ctx.json({ results }); }); diff --git a/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts b/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts index c55e616d..931853d8 100644 --- a/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts +++ b/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts @@ -104,7 +104,7 @@ export const useFileBrowserApp = (basePath: string, rootOverride?: string, initi setSearching(true); searchTimerRef.current = setTimeout(async () => { try { - const data = await filesRef.current.search(q); + const data = await filesRef.current.search(q, currentPath); setSearchResults(data.results); } catch { toast.error('Search failed'); diff --git a/src/workspaces/officerdev/src/hooks/useFilesAPI.ts b/src/workspaces/officerdev/src/hooks/useFilesAPI.ts index ace219dc..52f4ca12 100644 --- a/src/workspaces/officerdev/src/hooks/useFilesAPI.ts +++ b/src/workspaces/officerdev/src/hooks/useFilesAPI.ts @@ -24,8 +24,8 @@ export const useFilesAPI = (root: string = 'home') => { writeFile: (path: string, content: string) => client.post(withRoot('/file-browser/write'), { path, content }), - search: (query: string) => - client.get<{ results: DirEntry[] }>(withRoot(`/file-browser/search?q=${encodeURIComponent(query)}`)), + search: (query: string, path?: string) => + client.get<{ results: DirEntry[] }>(withRoot(`/file-browser/search?q=${encodeURIComponent(query)}${path ? `&path=${encodeURIComponent(path)}` : ''}`)), copy: (sources: string[], destination: string) => client.post(withRoot('/file-browser/copy'), {