mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
feat(#17): add commands and jobs to poll, download and update firmware
feat(#17): add commands and jobs to poll, download and update firmware feat(#17): update firmware modal feat(#17): add tests
This commit is contained in:
parent
93aac51182
commit
87b9b57c3d
13 changed files with 567 additions and 3 deletions
47
app/Jobs/FirmwareDownloadJob.php
Normal file
47
app/Jobs/FirmwareDownloadJob.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Firmware;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FirmwareDownloadJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
private Firmware $firmware;
|
||||
|
||||
public function __construct(Firmware $firmware)
|
||||
{
|
||||
$this->firmware = $firmware;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (! Storage::disk('public')->exists('firmwares')) {
|
||||
Storage::disk('public')->makeDirectory('firmwares');
|
||||
}
|
||||
|
||||
try {
|
||||
$filename = "FW{$this->firmware->version_tag}.bin";
|
||||
Http::sink(storage_path("app/public/firmwares/$filename"))
|
||||
->get($this->firmware->url);
|
||||
|
||||
$this->firmware->update([
|
||||
'storage_location' => "firmwares/$filename",
|
||||
]);
|
||||
} catch (ConnectionException $e) {
|
||||
Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
Log::error('An unexpected error occurred: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue