mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-14 12:23:33 +00:00
chore: stricter pint rules
This commit is contained in:
parent
16b2e8436e
commit
e535496a1e
30 changed files with 134 additions and 83 deletions
|
|
@ -128,8 +128,8 @@ class MashupCreateCommand extends Command
|
|||
required: true,
|
||||
default: 'Mashup',
|
||||
validate: fn (string $value) => match (true) {
|
||||
strlen($value) < 1 => 'The name must be at least 2 characters.',
|
||||
strlen($value) > 50 => 'The name must not exceed 50 characters.',
|
||||
mb_strlen($value) < 1 => 'The name must be at least 2 characters.',
|
||||
mb_strlen($value) > 50 => 'The name must not exceed 50 characters.',
|
||||
default => null,
|
||||
}
|
||||
);
|
||||
|
|
@ -149,7 +149,7 @@ class MashupCreateCommand extends Command
|
|||
$selectedPlugins = collect();
|
||||
$availablePlugins = $plugins->mapWithKeys(fn ($plugin) => [$plugin->id => $plugin->name])->toArray();
|
||||
|
||||
for ($i = 0; $i < $requiredCount; $i++) {
|
||||
for ($i = 0; $i < $requiredCount; ++$i) {
|
||||
$position = match ($i) {
|
||||
0 => 'first',
|
||||
1 => 'second',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
|||
|
||||
use App\Jobs\GenerateScreenJob;
|
||||
use Illuminate\Console\Command;
|
||||
use Throwable;
|
||||
|
||||
class ScreenGeneratorCommand extends Command
|
||||
{
|
||||
|
|
@ -31,7 +32,7 @@ class ScreenGeneratorCommand extends Command
|
|||
|
||||
try {
|
||||
$markup = view($view)->render();
|
||||
} catch (\Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
$this->error('Failed to render view: '.$e->getMessage());
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Device;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -67,7 +68,7 @@ class FetchProxyCloudResponses implements ShouldQueue
|
|||
$device->update([
|
||||
'current_screen_image' => $filename,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error("Failed to download and save image for device: {$device->mac_address}", [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
|
@ -95,7 +96,7 @@ class FetchProxyCloudResponses implements ShouldQueue
|
|||
]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error("Failed to fetch proxy cloud response for device: {$device->mac_address}", [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Firmware;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -40,7 +41,7 @@ class FirmwareDownloadJob implements ShouldQueue
|
|||
]);
|
||||
} catch (ConnectionException $e) {
|
||||
Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error('An unexpected error occurred: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Firmware;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -10,6 +11,7 @@ use Illuminate\Http\Client\ConnectionException;
|
|||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Log;
|
||||
|
||||
class FirmwarePollJob implements ShouldQueue
|
||||
{
|
||||
|
|
@ -28,7 +30,7 @@ class FirmwarePollJob implements ShouldQueue
|
|||
$response = Http::get('https://usetrmnl.com/api/firmware/latest')->json();
|
||||
|
||||
if (! is_array($response) || ! isset($response['version']) || ! isset($response['url'])) {
|
||||
\Log::error('Invalid firmware response format received');
|
||||
Log::error('Invalid firmware response format received');
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -48,9 +50,9 @@ class FirmwarePollJob implements ShouldQueue
|
|||
}
|
||||
|
||||
} catch (ConnectionException $e) {
|
||||
\Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Unexpected error in firmware polling: '.$e->getMessage());
|
||||
Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Log::error('Unexpected error in firmware polling: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ class Device extends Model
|
|||
// Ensure the voltage is within range
|
||||
if ($volts <= $min_volt) {
|
||||
return 0;
|
||||
} elseif ($volts >= $max_volt) {
|
||||
}
|
||||
if ($volts >= $max_volt) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +61,8 @@ class Device extends Model
|
|||
// Ensure the percentage is within range
|
||||
if ($percent <= 0) {
|
||||
return $min_volt;
|
||||
} elseif ($percent >= 100) {
|
||||
}
|
||||
if ($percent >= 100) {
|
||||
return $max_volt;
|
||||
}
|
||||
|
||||
|
|
@ -75,13 +77,16 @@ class Device extends Model
|
|||
$rssi = $this->last_rssi_level;
|
||||
if ($rssi >= 0) {
|
||||
return 0; // No signal (0 bars)
|
||||
} elseif ($rssi <= -80) {
|
||||
return 1; // Weak signal (1 bar)
|
||||
} elseif ($rssi <= -60) {
|
||||
return 2; // Moderate signal (2 bars)
|
||||
} else {
|
||||
return 3; // Strong signal (3 bars)
|
||||
}
|
||||
if ($rssi <= -80) {
|
||||
return 1; // Weak signal (1 bar)
|
||||
}
|
||||
if ($rssi <= -60) {
|
||||
return 2; // Moderate signal (2 bars)
|
||||
}
|
||||
|
||||
return 3; // Strong signal (3 bars)
|
||||
|
||||
}
|
||||
|
||||
public function getUpdateFirmwareAttribute(): bool
|
||||
|
|
@ -161,7 +166,7 @@ class Device extends Model
|
|||
|
||||
public function mirrorDevice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Device::class, 'mirror_device_id');
|
||||
return $this->belongsTo(self::class, 'mirror_device_id');
|
||||
}
|
||||
|
||||
public function updateFirmware(): BelongsTo
|
||||
|
|
|
|||
|
|
@ -90,12 +90,13 @@ class Plugin extends Model
|
|||
'data' => $this->data_payload,
|
||||
])->render(),
|
||||
])->render();
|
||||
} else {
|
||||
return view($this->render_markup_view, [
|
||||
'size' => $size,
|
||||
'data' => $this->data_payload,
|
||||
])->render();
|
||||
}
|
||||
|
||||
return view($this->render_markup_view, [
|
||||
'size' => $size,
|
||||
'data' => $this->data_payload,
|
||||
])->render();
|
||||
|
||||
}
|
||||
|
||||
return '<p>No render markup yet defined for this plugin.</p>';
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use URL;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -20,7 +21,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
public function boot(): void
|
||||
{
|
||||
if (app()->isProduction() && config('app.force_https')) {
|
||||
\URL::forceScheme('https');
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,14 @@ namespace App\Services;
|
|||
use App\Enums\ImageFormat;
|
||||
use App\Models\Device;
|
||||
use App\Models\Plugin;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Imagick;
|
||||
use ImagickException;
|
||||
use ImagickPixel;
|
||||
use Log;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use RuntimeException;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
use Wnx\SidecarBrowsershot\BrowsershotLambda;
|
||||
|
||||
|
|
@ -26,9 +31,9 @@ class ImageGenerationService
|
|||
BrowsershotLambda::html($markup)
|
||||
->windowSize(800, 480)
|
||||
->save($pngPath);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new \RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
|
@ -36,25 +41,25 @@ class ImageGenerationService
|
|||
->setOption('args', config('app.puppeteer_docker') ? ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'] : [])
|
||||
->windowSize(800, 480)
|
||||
->save($pngPath);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new \RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
switch ($device->image_format) {
|
||||
case ImageFormat::BMP3_1BIT_SRGB->value:
|
||||
try {
|
||||
ImageGenerationService::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
self::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
break;
|
||||
case ImageFormat::PNG_8BIT_GRAYSCALE->value:
|
||||
case ImageFormat::PNG_8BIT_256C->value:
|
||||
try {
|
||||
ImageGenerationService::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate, quantize: $device->image_format === ImageFormat::PNG_8BIT_GRAYSCALE);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
self::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate, quantize: $device->image_format === ImageFormat::PNG_8BIT_GRAYSCALE);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
break;
|
||||
case ImageFormat::AUTO->value:
|
||||
|
|
@ -62,33 +67,33 @@ class ImageGenerationService
|
|||
if (isset($device->last_firmware_version)
|
||||
&& version_compare($device->last_firmware_version, '1.5.2', '<')) {
|
||||
try {
|
||||
ImageGenerationService::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
self::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ImageGenerationService::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
self::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$device->update(['current_screen_image' => $uuid]);
|
||||
\Log::info("Device $device->id: updated with new image: $uuid");
|
||||
Log::info("Device $device->id: updated with new image: $uuid");
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ImagickException
|
||||
* @throws ImagickException
|
||||
*/
|
||||
private static function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
|
||||
{
|
||||
$imagick = new \Imagick($pngPath);
|
||||
$imagick->setImageType(\Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, \Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick = new Imagick($pngPath);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->setImageDepth(1);
|
||||
$imagick->stripImage();
|
||||
$imagick->setFormat('BMP3');
|
||||
|
|
@ -97,20 +102,20 @@ class ImageGenerationService
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \ImagickException
|
||||
* @throws ImagickException
|
||||
*/
|
||||
private static function convertToPngImageMagick(string $pngPath, ?int $width, ?int $height, ?int $rotate, $quantize = true): void
|
||||
{
|
||||
$imagick = new \Imagick($pngPath);
|
||||
$imagick = new Imagick($pngPath);
|
||||
if ($width !== 800 || $height !== 480) {
|
||||
$imagick->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true);
|
||||
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
|
||||
}
|
||||
if ($rotate !== null && $rotate !== 0) {
|
||||
$imagick->rotateImage(new ImagickPixel('black'), $rotate);
|
||||
}
|
||||
$imagick->setImageType(\Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
if ($quantize) {
|
||||
$imagick->quantizeImage(2, \Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
}
|
||||
$imagick->setImageDepth(8);
|
||||
$imagick->stripImage();
|
||||
|
|
@ -152,7 +157,7 @@ class ImageGenerationService
|
|||
) {
|
||||
// TODO cache image per device
|
||||
$plugin->update(['current_image' => null]);
|
||||
\Log::debug('Skip cache as devices with other dimensions exist');
|
||||
Log::debug('Skip cache as devices with other dimensions exist');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue