user()->plugins->contains($this->plugin), 403); abort_unless($this->plugin->plugin_type === 'image_webhook', 404); $this->name = $this->plugin->name; } protected array $rules = [ 'name' => 'required|string|max:255', 'checked_devices' => 'array', 'device_playlist_names' => 'array', 'device_playlists' => 'array', 'device_weekdays' => 'array', 'device_active_from' => 'array', 'device_active_until' => 'array', ]; public function updateName(): void { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); $this->validate(['name' => 'required|string|max:255']); $this->plugin->update(['name' => $this->name]); } public function addToPlaylist() { $this->validate([ 'checked_devices' => 'required|array|min:1', ]); foreach ($this->checked_devices as $deviceId) { if (!isset($this->device_playlists[$deviceId]) || empty($this->device_playlists[$deviceId])) { $this->addError('device_playlists.' . $deviceId, 'Please select a playlist for each device.'); return; } if ($this->device_playlists[$deviceId] === 'new') { if (!isset($this->device_playlist_names[$deviceId]) || empty($this->device_playlist_names[$deviceId])) { $this->addError('device_playlist_names.' . $deviceId, 'Playlist name is required when creating a new playlist.'); return; } } } foreach ($this->checked_devices as $deviceId) { $playlist = null; if ($this->device_playlists[$deviceId] === 'new') { $playlist = \App\Models\Playlist::create([ 'device_id' => $deviceId, 'name' => $this->device_playlist_names[$deviceId], 'weekdays' => !empty($this->device_weekdays[$deviceId] ?? null) ? $this->device_weekdays[$deviceId] : null, 'active_from' => $this->device_active_from[$deviceId] ?? null, 'active_until' => $this->device_active_until[$deviceId] ?? null, ]); } else { $playlist = \App\Models\Playlist::findOrFail($this->device_playlists[$deviceId]); } $maxOrder = $playlist->items()->max('order') ?? 0; // Image webhook plugins only support full layout $playlist->items()->create([ 'plugin_id' => $this->plugin->id, 'order' => $maxOrder + 1, ]); } $this->reset([ 'checked_devices', 'device_playlists', 'device_playlist_names', 'device_weekdays', 'device_active_from', 'device_active_until', ]); Flux::modal('add-to-playlist')->close(); } public function getDevicePlaylists($deviceId) { return \App\Models\Playlist::where('device_id', $deviceId)->get(); } public function hasAnyPlaylistSelected(): bool { foreach ($this->checked_devices as $deviceId) { if (isset($this->device_playlists[$deviceId]) && !empty($this->device_playlists[$deviceId])) { return true; } } return false; } public function deletePlugin(): void { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); $this->plugin->delete(); $this->redirect(route('plugins.image-webhook')); } public function getImagePath(): ?string { if (!$this->plugin->current_image) { return null; } $extensions = ['png', 'bmp']; foreach ($extensions as $ext) { $path = 'images/generated/'.$this->plugin->current_image.'.'.$ext; if (\Illuminate\Support\Facades\Storage::disk('public')->exists($path)) { return $path; } } return null; } }; ?>
This will also remove this instance from your playlists.