mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +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
|
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Device extends Model
|
||||
{
|
||||
|
|
@ -63,6 +64,10 @@ class Device extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
if ($this->update_firmware_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -72,6 +77,17 @@ class Device extends Model
|
|||
return $this->proxy_cloud_response['firmware_url'];
|
||||
}
|
||||
|
||||
if ($this->update_firmware_id) {
|
||||
$firmware = Firmware::find($this->update_firmware_id);
|
||||
if ($firmware) {
|
||||
if ($firmware->storage_location) {
|
||||
return Storage::disk('public')->url($firmware->storage_location);
|
||||
}
|
||||
|
||||
return $firmware->url;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -81,6 +97,10 @@ class Device extends Model
|
|||
$this->proxy_cloud_response = array_merge($this->proxy_cloud_response, ['update_firmware' => false]);
|
||||
$this->save();
|
||||
}
|
||||
if ($this->update_firmware_id) {
|
||||
$this->update_firmware_id = null;
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function playlists(): HasMany
|
||||
|
|
@ -117,4 +137,9 @@ class Device extends Model
|
|||
{
|
||||
return $this->belongsTo(Device::class, 'mirror_device_id');
|
||||
}
|
||||
|
||||
public function updateFirmware(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Firmware::class, 'update_firmware_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
app/Models/Firmware.php
Normal file
25
app/Models/Firmware.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Firmware extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'latest' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getLatest(): ?self
|
||||
{
|
||||
return self::where('latest', true)->first();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue