feat: add Windows drive switcher dropdown in FolderPicker

When navigating to a drive root on Windows (e.g. C:\), path.dirname
returns itself, disabling the "go up" button and trapping the user on
that drive. This adds a compact dropdown next to the up button that
lists all available drives (auto-detected via fs.accessSync), allowing
quick switching between drives. macOS/Linux are unaffected (empty array,
dropdown not rendered).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
xuxu777xuandClaude Opus 4.6 committed 2026-02-07 13:29:59 +08:00
1 parent 262b295f63
commit 3ae44a7277
2 files changed
+53 -1

No files matched your search

+18
View File
@@ -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<ErrorResponse>(