UNPKG

morphbox

Version:

Docker-based AI sandbox for development with Claude integration

50 lines (47 loc) 1.58 kB
import { e as error, j as json } from './index-3BbzJtgI.js'; import { promises } from 'fs'; import path from 'path'; import { W as WORKSPACE_DIR } from './workspace-CcQOwpY7.js'; import 'child_process'; import 'util'; function validatePath(requestPath) { const normalized = path.normalize(path.join(WORKSPACE_DIR, requestPath)); if (!normalized.startsWith(WORKSPACE_DIR)) { throw error(403, "Access denied: Path outside workspace directory"); } return normalized; } const POST = async ({ request }) => { try { const formData = await request.formData(); const file = formData.get("file"); const targetPath = formData.get("path") || "/"; if (!file) { throw error(400, "No file provided"); } const targetDir = validatePath(targetPath); await promises.mkdir(targetDir, { recursive: true }); const fileName = file.name; const filePath = path.join(targetDir, fileName); try { await promises.access(filePath); } catch { } const arrayBuffer = await file.arrayBuffer(); const buffer = Buffer.from(arrayBuffer); await promises.writeFile(filePath, buffer); const stats = await promises.stat(filePath); return json({ success: true, path: path.relative(WORKSPACE_DIR, filePath), size: stats.size, modified: stats.mtime.toISOString() }); } catch (err) { if (err instanceof Response) throw err; console.error("Error uploading file:", err); throw error(500, "Failed to upload file"); } }; export { POST }; //# sourceMappingURL=_server.ts-CWxjSUAX.js.map