diff --git a/config/services.php b/config/services.php index 3df6254..7c579cb 100644 --- a/config/services.php +++ b/config/services.php @@ -40,6 +40,7 @@ return [ 'proxy_refresh_minutes' => env('TRMNL_PROXY_REFRESH_MINUTES', 15), 'proxy_refresh_cron' => env('TRMNL_PROXY_REFRESH_CRON'), 'override_orig_icon' => env('TRMNL_OVERRIDE_ORIG_ICON', false), + 'image_url_timeout' => env('TRMNL_IMAGE_URL_TIMEOUT', null), ], - + ]; diff --git a/routes/api.php b/routes/api.php index 84b4373..ebc4fb9 100644 --- a/routes/api.php +++ b/routes/api.php @@ -77,7 +77,7 @@ Route::get('/display', function (Request $request) { $filename = basename($image_path); } - return response()->json([ + $response = [ 'status' => 0, 'image_url' => url('storage/'.$image_path), 'filename' => $filename, @@ -86,7 +86,13 @@ Route::get('/display', function (Request $request) { 'update_firmware' => $device->update_firmware, 'firmware_url' => $device->firmware_url, 'special_function' => 'sleep', - ]); + ]; + + if (config('services.trmnl.image_url_timeout')) { + $response['image_url_timeout'] = config('services.trmnl.image_url_timeout'); + } + + return response()->json($response); }); Route::get('/setup', function (Request $request) { diff --git a/tests/Feature/Api/DeviceEndpointsTest.php b/tests/Feature/Api/DeviceEndpointsTest.php index c690106..0fa1bbf 100644 --- a/tests/Feature/Api/DeviceEndpointsTest.php +++ b/tests/Feature/Api/DeviceEndpointsTest.php @@ -43,6 +43,48 @@ test('device can fetch display data with valid credentials', function () { ->last_firmware_version->toBe('1.0.0'); }); +test('display endpoint includes image_url_timeout when configured', function () { + $device = Device::factory()->create([ + 'mac_address' => '00:11:22:33:44:55', + 'api_key' => 'test-api-key', + ]); + + config(['services.trmnl.image_url_timeout' => 300]); + + $response = $this->withHeaders([ + 'id' => $device->mac_address, + 'access-token' => $device->api_key, + 'rssi' => -70, + 'battery_voltage' => 3.8, + 'fw-version' => '1.0.0', + ])->get('/api/display'); + + $response->assertOk() + ->assertJson([ + 'image_url_timeout' => 300, + ]); +}); + +test('display endpoint omits image_url_timeout when not configured', function () { + $device = Device::factory()->create([ + 'mac_address' => '00:11:22:33:44:55', + 'api_key' => 'test-api-key', + ]); + + config(['services.trmnl.image_url_timeout' => null]); + + $response = $this->withHeaders([ + 'id' => $device->mac_address, + 'access-token' => $device->api_key, + 'rssi' => -70, + 'battery_voltage' => 3.8, + 'fw-version' => '1.0.0', + ])->get('/api/display'); + + $response->assertOk() + ->assertJsonMissing(['image_url_timeout']); +}); + test('new device is auto-assigned to user with auto-assign enabled', function () { $user = User::factory()->create(['assign_new_devices' => true]);