mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-15 04:43:29 +00:00
Compare commits
No commits in common. "0aa38428f693dacf3b0c92760f9238952aa074ba" and "b96a96155d1b77f6765fcd2a07ad55b7d35b2a73" have entirely different histories.
0aa38428f6
...
b96a96155d
4 changed files with 19 additions and 28 deletions
|
|
@ -192,12 +192,8 @@ class Plugin extends Model
|
|||
$httpRequest = Http::withHeaders($headers);
|
||||
|
||||
if ($this->polling_verb === 'post' && $this->polling_body) {
|
||||
$contentType = (array_key_exists('Content-Type', $headers))
|
||||
? $headers['Content-Type']
|
||||
: 'application/json';
|
||||
|
||||
$resolvedBody = $this->resolveLiquidVariables($this->polling_body);
|
||||
$httpRequest = $httpRequest->withBody($resolvedBody, $contentType);
|
||||
$httpRequest = $httpRequest->withBody($resolvedBody);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
var data = trmnl.getSettings();
|
||||
trmnl.ui.apiKeyInput.value = data.api_key || "";
|
||||
trmnl.ui.baseURLInput.value = data.base_url || "";
|
||||
trmnl.ui.macAddressInput.value = data.mac_address || "";
|
||||
trmnl.ui.displayModeSelect.value = data.display_mode || "";
|
||||
|
||||
trmnl.ui.setup.style.display = "flex";
|
||||
|
|
@ -49,6 +50,7 @@
|
|||
|
||||
var apiKey = trmnl.ui.apiKeyInput.value;
|
||||
var baseURL = trmnl.ui.baseURLInput.value;
|
||||
var macAddress = trmnl.ui.macAddressInput.value;
|
||||
var displayMode = trmnl.ui.displayModeSelect.value;
|
||||
|
||||
if (!apiKey) {
|
||||
|
|
@ -58,6 +60,7 @@
|
|||
trmnl.saveSettings({
|
||||
api_key: apiKey,
|
||||
base_url: baseURL,
|
||||
mac_address: macAddress,
|
||||
display_mode: displayMode
|
||||
});
|
||||
|
||||
|
|
@ -81,6 +84,7 @@
|
|||
var apiKey = setup.api_key;
|
||||
var displayMode = setup.display_mode;
|
||||
var baseURL = setup.base_url || "https://your-byos-trmnl.com";
|
||||
var macAddress = setup.mac_address || "00:00:00:00:00:01";
|
||||
|
||||
document.body.classList.remove("dark", "night")
|
||||
if (displayMode) {
|
||||
|
|
@ -88,7 +92,8 @@
|
|||
}
|
||||
|
||||
var headers = {
|
||||
"Access-Token": apiKey
|
||||
"Access-Token": apiKey,
|
||||
"id": macAddress
|
||||
};
|
||||
|
||||
var url = baseURL + "/api/display";
|
||||
|
|
@ -205,6 +210,10 @@
|
|||
hasOverrides = true;
|
||||
}
|
||||
|
||||
if (key === "mac_address" && value) {
|
||||
newSettings.mac_address = value;
|
||||
hasOverrides = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOverrides) {
|
||||
|
|
@ -265,6 +274,7 @@
|
|||
// settings
|
||||
trmnl.ui.apiKeyInput = document.getElementById("api_key");
|
||||
trmnl.ui.baseURLInput = document.getElementById("base_url");
|
||||
trmnl.ui.macAddressInput = document.getElementById("mac_address");
|
||||
trmnl.ui.displayModeSelect = document.getElementById("display_mode");
|
||||
trmnl.ui.setup = document.getElementById("setup");
|
||||
|
||||
|
|
@ -459,6 +469,12 @@
|
|||
<img src="/mirror/assets/logo--brand.svg" alt="TRMNL Logo" />
|
||||
|
||||
<form onsubmit="return trmnl.saveSetup(event)">
|
||||
<fieldset>
|
||||
<label for="mac_address">Device MAC Address</label>
|
||||
<input name="mac_address" id="mac_address" type="text" placeholder="00:00:00:00:00:01" class="form-control"
|
||||
required />
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="api_key">Device API Key</label>
|
||||
<input name="api_key" id="api_key" type="text" placeholder="API Key" class="form-control" required />
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ new class extends Component
|
|||
|
||||
<flux:modal name="mirror-url" class="md:w-96">
|
||||
@php
|
||||
$mirrorUrl = url('/mirror/index.html') . '?api_key=' . urlencode($device->api_key);
|
||||
$mirrorUrl = url('/mirror/index.html') . '?mac_address=' . urlencode($device->mac_address) . '&api_key=' . urlencode($device->api_key);
|
||||
@endphp
|
||||
|
||||
<div class="space-y-6">
|
||||
|
|
|
|||
|
|
@ -72,27 +72,6 @@ test('updateDataPayload sends POST request with body when polling_verb is post',
|
|||
$request->body() === '{"query": "query { user { id name } }"}');
|
||||
});
|
||||
|
||||
test('updateDataPayload sends POST request with body with correct content type when not JSON content', function (): void {
|
||||
Http::fake([
|
||||
'https://example.com/api' => Http::response(['success' => true], 200),
|
||||
]);
|
||||
|
||||
$plugin = Plugin::factory()->create([
|
||||
'data_strategy' => 'polling',
|
||||
'polling_url' => 'https://example.com/api',
|
||||
'polling_verb' => 'post',
|
||||
'polling_body' => '<query><user id="123" name="John Doe"/></query>',
|
||||
'polling_header' => 'Content-Type: text/xml'
|
||||
]);
|
||||
|
||||
$plugin->updateDataPayload();
|
||||
|
||||
Http::assertSent(fn ($request): bool => $request->url() === 'https://example.com/api' &&
|
||||
$request->method() === 'POST' &&
|
||||
$request->hasHeader('Content-Type', 'text/xml') &&
|
||||
$request->body() === '<query><user id="123" name="John Doe"/></query>');
|
||||
});
|
||||
|
||||
test('updateDataPayload handles multiple URLs with IDX_ prefixes', function (): void {
|
||||
$plugin = Plugin::factory()->create([
|
||||
'data_strategy' => 'polling',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue