diff --git a/src/app/api/files/browse/route.ts b/src/app/api/files/browse/route.ts index a264bd4..d51674b 100644 --- a/src/app/api/files/browse/route.ts +++ b/src/app/api/files/browse/route.ts @@ -4,6 +4,21 @@ import path from 'path'; import os from 'os'; import type { ErrorResponse } from '@/types'; +function getWindowsDrives(): string[] { + if (process.platform !== 'win32') return []; + const drives: string[] = []; + for (let i = 65; i <= 90; i++) { + const drive = String.fromCharCode(i) + ':\\'; + try { + fs.accessSync(drive); + drives.push(drive); + } catch { + // drive not available + } + } + return drives; +} + // List only directories for folder browsing (no safety restriction since user is choosing where to work) export async function GET(request: NextRequest) { const { searchParams } = request.nextUrl; @@ -28,10 +43,13 @@ export async function GET(request: NextRequest) { })) .sort((a, b) => a.name.localeCompare(b.name)); + const drives = getWindowsDrives(); + return NextResponse.json({ current: resolvedDir, parent: path.dirname(resolvedDir) !== resolvedDir ? path.dirname(resolvedDir) : null, directories, + drives, }); } catch { return NextResponse.json( diff --git a/src/components/chat/FolderPicker.tsx b/src/components/chat/FolderPicker.tsx index d56bb8d..bf61862 100644 --- a/src/components/chat/FolderPicker.tsx +++ b/src/components/chat/FolderPicker.tsx @@ -11,6 +11,12 @@ import { DialogTitle, DialogFooter, } from '@/components/ui/dialog'; +import { + DropdownMenu, + DropdownMenuTrigger, + DropdownMenuContent, + DropdownMenuItem, +} from '@/components/ui/dropdown-menu'; import { Input } from '@/components/ui/input'; import { ScrollArea } from '@/components/ui/scroll-area'; @@ -23,6 +29,7 @@ interface BrowseResponse { current: string; parent: string | null; directories: FolderEntry[]; + drives?: string[]; } interface FolderPickerProps { @@ -38,6 +45,7 @@ export function FolderPicker({ open, onOpenChange, onSelect, initialPath }: Fold const [directories, setDirectories] = useState([]); const [loading, setLoading] = useState(false); const [pathInput, setPathInput] = useState(''); + const [drives, setDrives] = useState([]); const browse = useCallback(async (dir?: string) => { setLoading(true); @@ -52,6 +60,7 @@ export function FolderPicker({ open, onOpenChange, onSelect, initialPath }: Fold setParentDir(data.parent); setDirectories(data.directories); setPathInput(data.current); + setDrives(data.drives || []); } } catch { // silently fail @@ -108,7 +117,7 @@ export function FolderPicker({ open, onOpenChange, onSelect, initialPath }: Fold {/* Directory browser */}
- {/* Current path + go up */} + {/* Current path + go up + drive switcher */}
+ {drives.length > 0 && ( + + + + + + {drives.map((drive) => { + const letter = drive.charAt(0).toUpperCase(); + const isCurrent = currentDir.toUpperCase().startsWith(letter + ':'); + return ( + browse(drive)} + > + {letter}: + {drive} + + ); + })} + + + )} {currentDir}