From 309450e1b3582ddb17466fcb19dd5699915e8015 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Thu, 13 Feb 2025 13:06:04 +0100 Subject: [PATCH] feat ScreenGeneratorCommand, fix render endpoint * feat: signature var `view` added to ScreenGeneratorCommand * fix: /display endpoint responds current screen image from db --- app/Console/Commands/ScreenGeneratorCommand.php | 5 +++-- routes/api.php | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/ScreenGeneratorCommand.php b/app/Console/Commands/ScreenGeneratorCommand.php index 2a673d8..e9b8642 100644 --- a/app/Console/Commands/ScreenGeneratorCommand.php +++ b/app/Console/Commands/ScreenGeneratorCommand.php @@ -15,7 +15,7 @@ class ScreenGeneratorCommand extends Command * * @var string */ - protected $signature = 'trmnl:screen:generate {deviceId=1}'; + protected $signature = 'trmnl:screen:generate {deviceId=1} {view=trmnl}'; /** * The console command description. @@ -31,6 +31,7 @@ class ScreenGeneratorCommand extends Command { $deviceId = $this->argument('deviceId'); + $view = $this->argument('view'); $uuid = Uuid::uuid4()->toString(); $pngPath = public_path('storage/images/generated/').$uuid.'.png'; @@ -38,7 +39,7 @@ class ScreenGeneratorCommand extends Command // Generate PNG try { - Browsershot::html(view('trmnl')->render()) + Browsershot::html(view($view)->render()) ->windowSize(800, 480) ->save($pngPath); } catch (\Exception $e) { diff --git a/routes/api.php b/routes/api.php index d25daa2..b44e491 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,7 +24,9 @@ Route::get('/display', function (Request $request) { 'last_firmware_version' => $request->header('fw-version'), ]); - $image_path = collect(\Storage::disk('public')->files('/images/generated'))->first(fn ($file) => \Str::endsWith($file, '.bmp')); + $image_uuid = $device->current_screen_image; + + $image_path = 'images/generated/'.$image_uuid.'.bmp'; $filename = basename($image_path); return response()->json([