Files
wehub-resource-sync e30e75b5d4
Changesets / Create Version PR (push) Has been cancelled
Deploy Shadcn Registry / Deploy Production (push) Has been cancelled
Template Metrics / LOC + Bundle Size (push) Has been cancelled
Code Quality / Oxlint + Oxfmt (push) Has been cancelled
Code Quality / Template Sync (push) Has been cancelled
Code Quality / Build Changed Packages (push) Has been cancelled
Code Quality / Test Changed Packages (push) Has been cancelled
Deploy Expo Example / Deploy Production (push) Has been cancelled
Deploy Ink Example / Deploy Production (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.12) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

39 lines
1.3 KiB
TypeScript

import { readdir } from "node:fs/promises";
import { homedir } from "node:os";
import { resolve, dirname, join } from "node:path";
import { withFail } from "@/lib/http";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export type FsEntry = { name: string; path: string };
export type FsListing = {
path: string;
parent: string | null;
entries: FsEntry[];
};
const expand = (p: string): string =>
p.startsWith("~") ? join(homedir(), p.slice(1)) : p;
export const GET = withFail(async (request: Request) => {
// This lists arbitrary host directories for the local workspace picker —
// never expose it from a deployed instance.
if (process.env.NODE_ENV === "production") {
return new Response(null, { status: 404 });
}
const raw = new URL(request.url).searchParams.get("path");
const dir = resolve(raw ? expand(raw) : homedir());
const dirents = await readdir(dir, { withFileTypes: true });
const entries = dirents
.filter((dirent) => dirent.isDirectory() && !dirent.name.startsWith("."))
.map((dirent) => ({ name: dirent.name, path: join(dir, dirent.name) }))
.sort((a, b) => a.name.localeCompare(b.name));
const parent = dirname(dir);
return Response.json({
path: dir,
parent: parent === dir ? null : parent,
entries,
} satisfies FsListing);
});