feat ScreenGeneratorCommand, fix render endpoint

* feat: signature var `view` added to ScreenGeneratorCommand
* fix: /display endpoint responds current screen image from db
This commit is contained in:
Benjamin Nussbaum 2025-02-13 13:06:04 +01:00
parent 17e5dfd70e
commit 309450e1b3
2 changed files with 6 additions and 3 deletions

View file

@ -15,7 +15,7 @@ class ScreenGeneratorCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'trmnl:screen:generate {deviceId=1}'; protected $signature = 'trmnl:screen:generate {deviceId=1} {view=trmnl}';
/** /**
* The console command description. * The console command description.
@ -31,6 +31,7 @@ class ScreenGeneratorCommand extends Command
{ {
$deviceId = $this->argument('deviceId'); $deviceId = $this->argument('deviceId');
$view = $this->argument('view');
$uuid = Uuid::uuid4()->toString(); $uuid = Uuid::uuid4()->toString();
$pngPath = public_path('storage/images/generated/').$uuid.'.png'; $pngPath = public_path('storage/images/generated/').$uuid.'.png';
@ -38,7 +39,7 @@ class ScreenGeneratorCommand extends Command
// Generate PNG // Generate PNG
try { try {
Browsershot::html(view('trmnl')->render()) Browsershot::html(view($view)->render())
->windowSize(800, 480) ->windowSize(800, 480)
->save($pngPath); ->save($pngPath);
} catch (\Exception $e) { } catch (\Exception $e) {

View file

@ -24,7 +24,9 @@ Route::get('/display', function (Request $request) {
'last_firmware_version' => $request->header('fw-version'), '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); $filename = basename($image_path);
return response()->json([ return response()->json([