mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 07:27:47 +00:00
feat: proxy feature skipped when playlist is active
This commit is contained in:
parent
c8b21acb36
commit
6b40a2b836
1 changed files with 57 additions and 53 deletions
|
|
@ -22,52 +22,9 @@ class FetchProxyCloudResponses implements ShouldQueue
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
Device::where('proxy_cloud', true)->each(function ($device) {
|
Device::where('proxy_cloud', true)->each(function ($device) {
|
||||||
try {
|
if (!$device->getNextPlaylistItem()) {
|
||||||
$response = Http::withHeaders([
|
try {
|
||||||
'id' => $device->mac_address,
|
$response = Http::withHeaders([
|
||||||
'access-token' => $device->api_key,
|
|
||||||
'width' => 800,
|
|
||||||
'height' => 480,
|
|
||||||
'rssi' => $device->last_rssi_level,
|
|
||||||
'battery_voltage' => $device->last_battery_voltage,
|
|
||||||
'refresh-rate' => $device->default_refresh_interval,
|
|
||||||
'fw-version' => $device->last_firmware_version,
|
|
||||||
'accept-encoding' => 'identity;q=1,chunked;q=0.1,*;q=0',
|
|
||||||
'user-agent' => 'ESP32HTTPClient',
|
|
||||||
])->get(config('services.trmnl.proxy_base_url').'/api/display');
|
|
||||||
|
|
||||||
$device->update([
|
|
||||||
'proxy_cloud_response' => $response->json(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$imageUrl = $response->json('image_url');
|
|
||||||
$filename = $response->json('filename');
|
|
||||||
|
|
||||||
\Log::info('Response data: '.$imageUrl);
|
|
||||||
if (isset($imageUrl)) {
|
|
||||||
try {
|
|
||||||
$imageContents = Http::get($imageUrl)->body();
|
|
||||||
if (! Storage::disk('public')->exists("images/generated/{$filename}.bmp")) {
|
|
||||||
Storage::disk('public')->put(
|
|
||||||
"images/generated/{$filename}.bmp",
|
|
||||||
$imageContents
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$device->update([
|
|
||||||
'current_screen_image' => $filename,
|
|
||||||
]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error("Failed to download and save image for device: {$device->mac_address}", [
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::info("Successfully updated proxy cloud response for device: {$device->mac_address}");
|
|
||||||
|
|
||||||
if ($device->last_log_request) {
|
|
||||||
Http::withHeaders([
|
|
||||||
'id' => $device->mac_address,
|
'id' => $device->mac_address,
|
||||||
'access-token' => $device->api_key,
|
'access-token' => $device->api_key,
|
||||||
'width' => 800,
|
'width' => 800,
|
||||||
|
|
@ -78,17 +35,64 @@ class FetchProxyCloudResponses implements ShouldQueue
|
||||||
'fw-version' => $device->last_firmware_version,
|
'fw-version' => $device->last_firmware_version,
|
||||||
'accept-encoding' => 'identity;q=1,chunked;q=0.1,*;q=0',
|
'accept-encoding' => 'identity;q=1,chunked;q=0.1,*;q=0',
|
||||||
'user-agent' => 'ESP32HTTPClient',
|
'user-agent' => 'ESP32HTTPClient',
|
||||||
])->post(config('services.trmnl.proxy_base_url').'/api/log', $device->last_log_request);
|
])->get(config('services.trmnl.proxy_base_url') . '/api/display');
|
||||||
|
|
||||||
$device->update([
|
$device->update([
|
||||||
'last_log_request' => null,
|
'proxy_cloud_response' => $response->json(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$imageUrl = $response->json('image_url');
|
||||||
|
$filename = $response->json('filename');
|
||||||
|
|
||||||
|
\Log::info('Response data: ' . $imageUrl);
|
||||||
|
if (isset($imageUrl)) {
|
||||||
|
try {
|
||||||
|
$imageContents = Http::get($imageUrl)->body();
|
||||||
|
if (!Storage::disk('public')->exists("images/generated/{$filename}.bmp")) {
|
||||||
|
Storage::disk('public')->put(
|
||||||
|
"images/generated/{$filename}.bmp",
|
||||||
|
$imageContents
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$device->update([
|
||||||
|
'current_screen_image' => $filename,
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error("Failed to download and save image for device: {$device->mac_address}", [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info("Successfully updated proxy cloud response for device: {$device->mac_address}");
|
||||||
|
|
||||||
|
if ($device->last_log_request) {
|
||||||
|
Http::withHeaders([
|
||||||
|
'id' => $device->mac_address,
|
||||||
|
'access-token' => $device->api_key,
|
||||||
|
'width' => 800,
|
||||||
|
'height' => 480,
|
||||||
|
'rssi' => $device->last_rssi_level,
|
||||||
|
'battery_voltage' => $device->last_battery_voltage,
|
||||||
|
'refresh-rate' => $device->default_refresh_interval,
|
||||||
|
'fw-version' => $device->last_firmware_version,
|
||||||
|
'accept-encoding' => 'identity;q=1,chunked;q=0.1,*;q=0',
|
||||||
|
'user-agent' => 'ESP32HTTPClient',
|
||||||
|
])->post(config('services.trmnl.proxy_base_url') . '/api/log', $device->last_log_request);
|
||||||
|
|
||||||
|
$device->update([
|
||||||
|
'last_log_request' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error("Failed to fetch proxy cloud response for device: {$device->mac_address}", [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
} catch (\Exception $e) {
|
Log::info("Skipping device: {$device->mac_address} as it has a pending playlist item.");
|
||||||
Log::error("Failed to fetch proxy cloud response for device: {$device->mac_address}", [
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue