query('path', ''); $abs = realpath($path); if (!$abs || !str_starts_with($abs, '/workspace')) { return response()->json(['error' => 'Access denied'], 403); } if (!is_file($abs)) { return response()->json(['error' => 'File not found'], 404); } $raw = file_get_contents($abs); $content = mb_convert_encoding($raw, 'UTF-8', 'UTF-8'); // strip non-UTF8 bytes that would break json_encode $content = mb_convert_encoding($raw, 'UTF-8', mb_detect_encoding($raw, 'UTF-8,ISO-8859-1,Windows-1252', true) ?: 'UTF-8'); return response()->json(['path' => $abs, 'content' => $content]); } }