Add image caching for playlist items

This commit is contained in:
zv0n 2025-05-01 19:06:28 +02:00
parent 81f721099c
commit 6bfd9a2d8b
6 changed files with 173 additions and 85 deletions

View file

@ -1,6 +1,7 @@
<?php
use App\Jobs\GenerateScreenJob;
use App\Jobs\GeneratePlaylistItemJob;
use App\Models\Device;
use App\Models\User;
use Illuminate\Http\Request;
@ -46,28 +47,33 @@ Route::get('/display', function (Request $request) {
// Get current screen image from mirror device or continue if not available
if (! $image_uuid = $device->mirrorDevice?->current_screen_image) {
$refreshTimeOverride = null;
$nextPlaylistItem = $device->getNextPlaylistItem();
// Skip if cloud proxy is enabled for the device
if (! $device->proxy_cloud || $device->getNextPlaylistItem()) {
$playlistItem = $device->getNextPlaylistItem();
if ($playlistItem) {
$refreshTimeOverride = $playlistItem->playlist()->first()->refresh_time;
$plugin = $playlistItem->plugin;
if (! $device->proxy_cloud || $nextPlaylistItem) {
if ($nextPlaylistItem) {
$refreshTimeOverride = $nextPlaylistItem->playlist()->first()->refresh_time;
$plugin = $nextPlaylistItem->plugin;
// Check and update stale data if needed
if ($plugin->isDataStale()) {
if ($plugin->isDataStale() || $nextPlaylistItem->last_displayed_at == null) {
$plugin->updateDataPayload();
}
$playlistItem->update(['last_displayed_at' => now()]);
if ($plugin->render_markup) {
$markup = Blade::render($plugin->render_markup, ['data' => $plugin->data_payload]);
} elseif ($plugin->render_markup_view) {
$markup = view($plugin->render_markup_view, ['data' => $plugin->data_payload])->render();
}
if ($plugin->render_markup) {
$markup = Blade::render($plugin->render_markup, ['data' => $plugin->data_payload]);
} elseif ($plugin->render_markup_view) {
$markup = view($plugin->render_markup_view, ['data' => $plugin->data_payload])->render();
}
GenerateScreenJob::dispatchSync($device->id, $markup);
GeneratePlaylistItemJob::dispatchSync($nextPlaylistItem->id, $markup);
}
}
$nextPlaylistItem->refresh();
if ($nextPlaylistItem->current_image != null)
{
$nextPlaylistItem->update(['last_displayed_at' => now()]);
$device->update(['current_screen_image' => $nextPlaylistItem->current_image]);
}
}