45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Spatie\RouteAttributes\Attributes\Get;
|
|
use Spatie\RouteAttributes\Attributes\Middleware;
|
|
|
|
#[Middleware('web')]
|
|
class PageController extends Controller
|
|
{
|
|
#[Get('/')]
|
|
public function index()
|
|
{
|
|
return view('index');
|
|
}
|
|
|
|
#[Get('/email-convert')]
|
|
public function emailConvert()
|
|
{
|
|
$workingDir = env('WORKING_DIR', 'working');
|
|
return view('email_convert', compact('workingDir'));
|
|
}
|
|
|
|
#[Get('/workspace-file')]
|
|
public function readFile(Request $request)
|
|
{
|
|
$path = $request->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]);
|
|
}
|
|
}
|