morphbox
Version:
Docker-based AI sandbox for development with Claude integration
45 lines (42 loc) • 1.32 kB
JavaScript
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 DELETE = async ({ request }) => {
try {
const { path: filePath } = await request.json();
if (!filePath) {
throw error(400, "Path is required");
}
const fullPath = validatePath(filePath);
const stats = await promises.stat(fullPath);
if (stats.isDirectory()) {
await promises.rmdir(fullPath, { recursive: true });
} else {
await promises.unlink(fullPath);
}
return json({
success: true,
message: "File deleted successfully",
path: filePath
});
} catch (err) {
if (err instanceof Response) throw err;
if (err.code === "ENOENT") {
throw error(404, "File not found");
}
console.error("Error deleting file:", err);
throw error(500, "Failed to delete file");
}
};
export { DELETE };
//# sourceMappingURL=_server.ts-CQJkBQiu.js.map