Files
lucent-laravel/src/Http/Controller/BuildController.php
T

65 lines
1.6 KiB
PHP
Raw Normal View History

2023-10-04 23:48:12 +03:00
<?php
namespace Lucent\Http\Controller;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Artisan;
use Lucent\Channel\ChannelService;
use Lucent\Svelte\Svelte;
use function Lucent\Response\ok;
class BuildController extends Controller
{
public function __construct(
public readonly Svelte $svelte,
public readonly ChannelService $channelService,
)
{
}
public function build()
{
exec("cd ".base_path(). " && php8.2 artisan {$this->channelService->channel->generateCommand} > /dev/null 2>&1 & echo $!",$op);
$pid = (int)$op[0];
return redirect($this->channelService->channel->lucentUrl . "/build-report");
}
public function report(): View
{
return $this->svelte->render(
layout: "channel",
view: "buildReport",
title: "Build Report",
);
}
public function reportSource()
{
return response()->stream(function () {
while (true) {
$curDate = time();
echo 'data: {"time": "' . $curDate . '"}';
echo "\n\n";
logger( $curDate);
ob_flush();
flush();
// Break the loop if the client aborted the connection (closed the page)
if (connection_aborted()) {break;}
sleep(2); // 50ms
}
}, 200, [
'Cache-Control' => 'no-cache',
'X-Accel-Buffering' => 'no',
'Content-Type' => 'text/event-stream',
]);
}
}