Add depth-limited filesystem browsing

This commit is contained in:
Shantur Rathore
2025-11-17 21:16:10 +00:00
parent 719a9c9c74
commit f53564bb06
4 changed files with 215 additions and 25 deletions

View File

@@ -8,6 +8,7 @@ interface RouteDeps {
const FilesystemQuerySchema = z.object({
path: z.string().optional(),
depth: z.coerce.number().int().min(1).max(10).default(2),
})
export function registerFilesystemRoutes(app: FastifyInstance, deps: RouteDeps) {
@@ -16,7 +17,7 @@ export function registerFilesystemRoutes(app: FastifyInstance, deps: RouteDeps)
const targetPath = query.path ?? "."
try {
return deps.fileSystemBrowser.list(targetPath)
return deps.fileSystemBrowser.list(targetPath, query.depth)
} catch (error) {
reply.code(400)
return { error: (error as Error).message }