import { t as Exception } from "./const-Dy5RfQqP.js";
import { i as useRequestHandler } from "./request-handler-guINVc1G.js";
import { Writable } from "node:stream";
//#region .svelte-kit/adapter-bun/entries/endpoints/fs/project/_server.ts.js
/**
* To request a project file, use the following URL:
* /fs/project?path=path/to/file
* The path must be relative to /client
* Only the client is handled for now
*/
var GET = useRequestHandler(({ event, project }) => {
	const path = event.url.searchParams.get("path");
	if (!path) throw new Exception("Bad Request", "Missing path query param", 400);
	const stream = project.client.fs.getFile(decodeURIComponent(path).replace(/\?url$/, "")).readStream();
	return new Response(stream);
});
/**
* To post a project file, use the following URL:
* /fs/project?path=path/to/file
* The path must be relative to /client
* Only the client is handled for now
*/
var POST = useRequestHandler(async ({ event, project }) => {
	const path = event.url.searchParams.get("path");
	if (!path) throw new Exception("Bad Request", "Missing path query param", 400);
	const file = project.client.fs.getFile(decodeURIComponent(path).replace(/\?url$/, ""));
	if (!event.request.body) throw new Exception("Bad Request", "Missing body", 400);
	const stream = file.getWriteStream();
	await event.request.body.pipeTo(Writable.toWeb(stream));
	return Response.json({ success: true });
});
//#endregion
export { GET, POST };

//# sourceMappingURL=_server.ts-DlC2sxcm.js.map