mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 15:37:53 +00:00
feat: add header support for plugin data polling
This commit is contained in:
parent
a45684d940
commit
282fdac583
3 changed files with 72 additions and 34 deletions
31
README.md
31
README.md
|
|
@ -114,6 +114,20 @@ Server is ready. Visit tab "Ports" in VSCode and visit the "Forwarded Address" i
|
||||||
|
|
||||||
Login with user / password `admin@example.com` / `admin@example.com`
|
Login with user / password `admin@example.com` / `admin@example.com`
|
||||||
|
|
||||||
|
### Demo Plugins
|
||||||
|
|
||||||
|
Run the ExampleReceiptsSeeder to seed the database with example plugins:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan db:seed --class=ExampleReceiptsSeeder
|
||||||
|
```
|
||||||
|
|
||||||
|
* Zen Quotes
|
||||||
|
* This Day in History
|
||||||
|
* Weather
|
||||||
|
* Train Departure Monitor
|
||||||
|
* Home Assistant
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
#### Environment Variables
|
#### Environment Variables
|
||||||
|
|
@ -252,29 +266,18 @@ Here are some features and improvements that are open for contribution:
|
||||||
|
|
||||||
##### 🔌 Plugin System
|
##### 🔌 Plugin System
|
||||||
|
|
||||||
- ~~Enable configurable plugins via the Web Interface.~~ ✅
|
|
||||||
- Ensure compatibility with the trmnl-laravel package.
|
- Ensure compatibility with the trmnl-laravel package.
|
||||||
- Implement auto-discovery for plugins.
|
- Implement auto-discovery for plugins.
|
||||||
|
|
||||||
##### ⏳ Scheduling / Playlists
|
|
||||||
|
|
||||||
- Move task scheduling from console.php to a Web Interface.
|
|
||||||
- ~~Allow users to configure custom schedule intervals.~~ ✅
|
|
||||||
|
|
||||||
##### 🖥️ “Native” Plugins
|
##### 🖥️ “Native” Plugins
|
||||||
- Add built-in plugins such as (as an example):
|
|
||||||
- ☁️ Weather
|
|
||||||
- 💬 Quotes
|
|
||||||
- 🏡 Home Assistant integration
|
|
||||||
- Provide Web UI controls to enable/disable plugins.
|
|
||||||
|
|
||||||
##### 📦 Visual Studio Code Devcontainer
|
- Architecture for native plugins.
|
||||||
* ~~Add a .devcontainer to this repo for easier development with Docker.~~ ✅
|
- Configuration UI
|
||||||
|
|
||||||
##### Improve Code Coverage
|
##### Improve Code Coverage
|
||||||
|
|
||||||
- Expand Pest tests to cover more functionality.
|
- Expand Pest tests to cover more functionality.
|
||||||
- Increase code coverage (currently at 86.9%).
|
- Increase code coverage
|
||||||
|
|
||||||
### 🤝 Contribution
|
### 🤝 Contribution
|
||||||
Contributions are welcome! If you’d like to improve the project, follow these steps:
|
Contributions are welcome! If you’d like to improve the project, follow these steps:
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,20 @@ class Plugin extends Model
|
||||||
public function updateDataPayload(): void
|
public function updateDataPayload(): void
|
||||||
{
|
{
|
||||||
if ($this->data_strategy === 'polling' && $this->polling_url) {
|
if ($this->data_strategy === 'polling' && $this->polling_url) {
|
||||||
$response = Http::withHeaders(['User-Agent' => 'usetrmnl/byos_laravel', 'Accept' => 'application/json'])
|
// Parse headers from polling_header string
|
||||||
|
$headers = ['User-Agent' => 'usetrmnl/byos_laravel', 'Accept' => 'application/json'];
|
||||||
|
|
||||||
|
if ($this->polling_header) {
|
||||||
|
$headerLines = explode("\n", trim($this->polling_header));
|
||||||
|
foreach ($headerLines as $line) {
|
||||||
|
$parts = explode(':', $line, 2);
|
||||||
|
if (count($parts) === 2) {
|
||||||
|
$headers[trim($parts[0])] = trim($parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = Http::withHeaders($headers)
|
||||||
->get($this->polling_url)
|
->get($this->polling_url)
|
||||||
->json();
|
->json();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,24 @@ new class extends Component {
|
||||||
public function updateData()
|
public function updateData()
|
||||||
{
|
{
|
||||||
if ($this->plugin->data_strategy === 'polling') {
|
if ($this->plugin->data_strategy === 'polling') {
|
||||||
$response = Http::get($this->plugin->polling_url)->json();
|
// Parse headers from polling_header string
|
||||||
$this->plugin->update(['data_payload' => $response]);
|
$headers = ['User-Agent' => 'usetrmnl/byos_laravel', 'Accept' => 'application/json'];
|
||||||
|
|
||||||
|
if ($this->plugin->polling_header) {
|
||||||
|
$headerLines = explode("\n", trim($this->plugin->polling_header));
|
||||||
|
foreach ($headerLines as $line) {
|
||||||
|
$parts = explode(':', $line, 2);
|
||||||
|
if (count($parts) === 2) {
|
||||||
|
$headers[trim($parts[0])] = trim($parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = Http::withHeaders($headers)
|
||||||
|
->get($this->plugin->polling_url)
|
||||||
|
->json();
|
||||||
|
|
||||||
|
$this->plugin->update(['data_payload' => $response]);
|
||||||
$this->data_payload = json_encode($response);
|
$this->data_payload = json_encode($response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -289,8 +304,15 @@ HTML;
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<flux:input label="Polling Header" wire:model="polling_header" id="polling_header"
|
<flux:textarea
|
||||||
class="block mt-1 w-full" type="text" name="polling_header" autofocus/>
|
label="Polling Headers (one per line, format: Header: Value)"
|
||||||
|
wire:model="polling_header"
|
||||||
|
id="polling_header"
|
||||||
|
class="block mt-1 w-full font-mono"
|
||||||
|
name="polling_header"
|
||||||
|
rows="3"
|
||||||
|
placeholder="Authorization: Bearer ey.******* Content-Type: application/json"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue