mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 15:37:53 +00:00
Move current_image caching to plugins
This commit is contained in:
parent
6bfd9a2d8b
commit
4aa67ce02d
6 changed files with 18 additions and 18 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\PlaylistItem;
|
use App\Models\Plugin;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Spatie\Browsershot\Browsershot;
|
use Spatie\Browsershot\Browsershot;
|
||||||
|
|
@ -62,8 +62,8 @@ class CommonFunctions
|
||||||
public static function cleanupFolder(): void
|
public static function cleanupFolder(): void
|
||||||
{
|
{
|
||||||
$activeDeviceImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
$activeDeviceImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
||||||
$activePlaylistImageUuids = PlaylistItem::pluck('current_image')->filter()->toArray();
|
$activePluginImageUuids = Plugin::pluck('current_image')->filter()->toArray();
|
||||||
$activeImageUuids = array_merge($activeDeviceImageUuids, $activePlaylistImageUuids);
|
$activeImageUuids = array_merge($activeDeviceImageUuids, $activePluginImageUuids);
|
||||||
|
|
||||||
$files = Storage::disk('public')->files('/images/generated/');
|
$files = Storage::disk('public')->files('/images/generated/');
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Models\PlaylistItem;
|
use App\Models\Plugin;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class GeneratePlaylistItemJob implements ShouldQueue
|
class GeneratePluginJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ class GeneratePlaylistItemJob implements ShouldQueue
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly int $playlistItemId,
|
private readonly int $pluginId,
|
||||||
private readonly string $markup
|
private readonly string $markup
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
@ -28,8 +28,8 @@ class GeneratePlaylistItemJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
$newImageUuid = CommonFunctions::generateImage($this->markup);
|
$newImageUuid = CommonFunctions::generateImage($this->markup);
|
||||||
|
|
||||||
PlaylistItem::find($this->playlistItemId)->update(['current_image' => $newImageUuid]);
|
Plugin::find($this->pluginId)->update(['current_image' => $newImageUuid]);
|
||||||
\Log::info("Playlist item $this->playlistItemId: updated with new image: $newImageUuid");
|
\Log::info("Plugin $this->pluginId: updated with new image: $newImageUuid");
|
||||||
|
|
||||||
CommonFunctions::cleanupFolder();
|
CommonFunctions::cleanupFolder();
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,6 @@ class PlaylistItem extends Model
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_active' => 'boolean',
|
'is_active' => 'boolean',
|
||||||
'last_displayed_at' => 'datetime',
|
'last_displayed_at' => 'datetime',
|
||||||
'current_image' => 'string',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function playlist(): BelongsTo
|
public function playlist(): BelongsTo
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class Plugin extends Model
|
||||||
'data_payload' => 'json',
|
'data_payload' => 'json',
|
||||||
'data_payload_updated_at' => 'datetime',
|
'data_payload_updated_at' => 'datetime',
|
||||||
'is_native' => 'boolean',
|
'is_native' => 'boolean',
|
||||||
|
'current_image' => 'string',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static function boot()
|
protected static function boot()
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ return new class extends Migration
|
||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('playlist_items', function (Blueprint $table) {
|
Schema::table('plugins', function (Blueprint $table) {
|
||||||
$table->string('current_image')->nullable()->after('is_active');
|
$table->string('current_image')->nullable()->after('data_payload_updated_at');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ return new class extends Migration
|
||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('playlist_items', function (Blueprint $table) {
|
Schema::table('plugins', function (Blueprint $table) {
|
||||||
$table->dropColumn('current_image');
|
$table->dropColumn('current_image');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Jobs\GenerateScreenJob;
|
use App\Jobs\GenerateScreenJob;
|
||||||
use App\Jobs\GeneratePlaylistItemJob;
|
use App\Jobs\GeneratePluginJob;
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
@ -55,7 +55,7 @@ Route::get('/display', function (Request $request) {
|
||||||
$plugin = $nextPlaylistItem->plugin;
|
$plugin = $nextPlaylistItem->plugin;
|
||||||
|
|
||||||
// Check and update stale data if needed
|
// Check and update stale data if needed
|
||||||
if ($plugin->isDataStale() || $nextPlaylistItem->last_displayed_at == null) {
|
if ($plugin->isDataStale() || $plugin->current_image == null) {
|
||||||
$plugin->updateDataPayload();
|
$plugin->updateDataPayload();
|
||||||
|
|
||||||
if ($plugin->render_markup) {
|
if ($plugin->render_markup) {
|
||||||
|
|
@ -64,16 +64,16 @@ Route::get('/display', function (Request $request) {
|
||||||
$markup = view($plugin->render_markup_view, ['data' => $plugin->data_payload])->render();
|
$markup = view($plugin->render_markup_view, ['data' => $plugin->data_payload])->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratePlaylistItemJob::dispatchSync($nextPlaylistItem->id, $markup);
|
GeneratePluginJob::dispatchSync($plugin->id, $markup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$nextPlaylistItem->refresh();
|
$plugin->refresh();
|
||||||
|
|
||||||
if ($nextPlaylistItem->current_image != null)
|
if ($plugin->current_image != null)
|
||||||
{
|
{
|
||||||
$nextPlaylistItem->update(['last_displayed_at' => now()]);
|
$nextPlaylistItem->update(['last_displayed_at' => now()]);
|
||||||
$device->update(['current_screen_image' => $nextPlaylistItem->current_image]);
|
$device->update(['current_screen_image' => $plugin->current_image]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue