feat: add support for png

feat: add tests

chore: update dependencies
This commit is contained in:
Benjamin Nussbaum 2025-04-24 19:31:57 +02:00
parent f1fafe7ef0
commit b4dea89fad
6 changed files with 250 additions and 94 deletions

View file

@ -44,13 +44,17 @@ class FetchProxyCloudResponses implements ShouldQueue
$imageUrl = $response->json('image_url');
$filename = $response->json('filename');
parse_str(parse_url($imageUrl)['query'] ?? '', $queryParams);
$imageType = urldecode($queryParams['response-content-type'] ?? 'image/bmp');
$imageExtension = $imageType === 'image/png' ? 'png' : 'bmp';
\Log::info('Response data: '.$imageUrl);
if (isset($imageUrl)) {
try {
$imageContents = Http::get($imageUrl)->body();
if (! Storage::disk('public')->exists("images/generated/{$filename}.bmp")) {
if (! Storage::disk('public')->exists("images/generated/{$filename}.{$imageExtension}")) {
Storage::disk('public')->put(
"images/generated/{$filename}.bmp",
"images/generated/{$filename}.{$imageExtension}",
$imageContents
);
}

179
composer.lock generated
View file

@ -1354,16 +1354,16 @@
},
{
"name": "keepsuit/liquid",
"version": "v0.8.0",
"version": "v0.8.1",
"source": {
"type": "git",
"url": "https://github.com/keepsuit/php-liquid.git",
"reference": "50a0f1c6872821fa296c1c4564125b54b98651ef"
"reference": "efbce11b94490996a5227cbc24315d2edb060c06"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/keepsuit/php-liquid/zipball/50a0f1c6872821fa296c1c4564125b54b98651ef",
"reference": "50a0f1c6872821fa296c1c4564125b54b98651ef",
"url": "https://api.github.com/repos/keepsuit/php-liquid/zipball/efbce11b94490996a5227cbc24315d2edb060c06",
"reference": "efbce11b94490996a5227cbc24315d2edb060c06",
"shasum": ""
},
"require": {
@ -1372,8 +1372,8 @@
},
"require-dev": {
"laravel/pint": "^1.2",
"pestphp/pest": "^2.7",
"pestphp/pest-plugin-arch": "^2.2",
"pestphp/pest": "^2.36 || ^3.0",
"pestphp/pest-plugin-arch": "^2.7 || ^3.0",
"phpbench/phpbench": "dev-master",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^2.0",
@ -1409,22 +1409,22 @@
],
"support": {
"issues": "https://github.com/keepsuit/php-liquid/issues",
"source": "https://github.com/keepsuit/php-liquid/tree/v0.8.0"
"source": "https://github.com/keepsuit/php-liquid/tree/v0.8.1"
},
"time": "2025-02-23T13:47:09+00:00"
"time": "2025-04-22T07:33:48+00:00"
},
{
"name": "laravel/framework",
"version": "v12.8.1",
"version": "v12.10.2",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "d1ea3566f6e0cad34834c6d18db0bf995438eb87"
"reference": "0f123cc857bc177abe4d417448d4f7164f71802a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/d1ea3566f6e0cad34834c6d18db0bf995438eb87",
"reference": "d1ea3566f6e0cad34834c6d18db0bf995438eb87",
"url": "https://api.github.com/repos/laravel/framework/zipball/0f123cc857bc177abe4d417448d4f7164f71802a",
"reference": "0f123cc857bc177abe4d417448d4f7164f71802a",
"shasum": ""
},
"require": {
@ -1533,7 +1533,7 @@
"league/flysystem-sftp-v3": "^3.25.1",
"mockery/mockery": "^1.6.10",
"orchestra/testbench-core": "^10.0.0",
"pda/pheanstalk": "^5.0.6",
"pda/pheanstalk": "^5.0.6|^7.0.0",
"php-http/discovery": "^1.15",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.5.35|^11.5.3|^12.0.1",
@ -1626,7 +1626,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2025-04-08T19:58:59+00:00"
"time": "2025-04-24T14:11:20+00:00"
},
{
"name": "laravel/prompts",
@ -1689,16 +1689,16 @@
},
{
"name": "laravel/sanctum",
"version": "v4.0.8",
"version": "v4.1.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/sanctum.git",
"reference": "ec1dd9ddb2ab370f79dfe724a101856e0963f43c"
"reference": "4e4ced5023e9d8949214e0fb43d9f4bde79c7166"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/sanctum/zipball/ec1dd9ddb2ab370f79dfe724a101856e0963f43c",
"reference": "ec1dd9ddb2ab370f79dfe724a101856e0963f43c",
"url": "https://api.github.com/repos/laravel/sanctum/zipball/4e4ced5023e9d8949214e0fb43d9f4bde79c7166",
"reference": "4e4ced5023e9d8949214e0fb43d9f4bde79c7166",
"shasum": ""
},
"require": {
@ -1749,7 +1749,7 @@
"issues": "https://github.com/laravel/sanctum/issues",
"source": "https://github.com/laravel/sanctum"
},
"time": "2025-01-26T19:34:36+00:00"
"time": "2025-04-22T13:53:47+00:00"
},
{
"name": "laravel/serializable-closure",
@ -1880,16 +1880,16 @@
},
{
"name": "league/commonmark",
"version": "2.6.1",
"version": "2.6.2",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "d990688c91cedfb69753ffc2512727ec646df2ad"
"reference": "06c3b0bf2540338094575612f4a1778d0d2d5e94"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/d990688c91cedfb69753ffc2512727ec646df2ad",
"reference": "d990688c91cedfb69753ffc2512727ec646df2ad",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/06c3b0bf2540338094575612f4a1778d0d2d5e94",
"reference": "06c3b0bf2540338094575612f4a1778d0d2d5e94",
"shasum": ""
},
"require": {
@ -1983,7 +1983,7 @@
"type": "tidelift"
}
],
"time": "2024-12-29T14:10:59+00:00"
"time": "2025-04-18T21:09:27+00:00"
},
{
"name": "league/config",
@ -2431,16 +2431,16 @@
},
{
"name": "livewire/flux",
"version": "v2.1.2",
"version": "v2.1.4",
"source": {
"type": "git",
"url": "https://github.com/livewire/flux.git",
"reference": "3fad9b78f446926b1b851bd8f12ced7649c62368"
"reference": "a19709fc94f5a1b795ce24ad42662bd398c19371"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/livewire/flux/zipball/3fad9b78f446926b1b851bd8f12ced7649c62368",
"reference": "3fad9b78f446926b1b851bd8f12ced7649c62368",
"url": "https://api.github.com/repos/livewire/flux/zipball/a19709fc94f5a1b795ce24ad42662bd398c19371",
"reference": "a19709fc94f5a1b795ce24ad42662bd398c19371",
"shasum": ""
},
"require": {
@ -2488,22 +2488,22 @@
],
"support": {
"issues": "https://github.com/livewire/flux/issues",
"source": "https://github.com/livewire/flux/tree/v2.1.2"
"source": "https://github.com/livewire/flux/tree/v2.1.4"
},
"time": "2025-03-31T21:08:37+00:00"
"time": "2025-04-14T11:59:19+00:00"
},
{
"name": "livewire/livewire",
"version": "v3.6.2",
"version": "v3.6.3",
"source": {
"type": "git",
"url": "https://github.com/livewire/livewire.git",
"reference": "8f8914731f5eb43b6bb145d87c8d5a9edfc89313"
"reference": "56aa1bb63a46e06181c56fa64717a7287e19115e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/livewire/livewire/zipball/8f8914731f5eb43b6bb145d87c8d5a9edfc89313",
"reference": "8f8914731f5eb43b6bb145d87c8d5a9edfc89313",
"url": "https://api.github.com/repos/livewire/livewire/zipball/56aa1bb63a46e06181c56fa64717a7287e19115e",
"reference": "56aa1bb63a46e06181c56fa64717a7287e19115e",
"shasum": ""
},
"require": {
@ -2558,7 +2558,7 @@
"description": "A front-end framework for Laravel.",
"support": {
"issues": "https://github.com/livewire/livewire/issues",
"source": "https://github.com/livewire/livewire/tree/v3.6.2"
"source": "https://github.com/livewire/livewire/tree/v3.6.3"
},
"funding": [
{
@ -2566,7 +2566,7 @@
"type": "github"
}
],
"time": "2025-03-12T20:24:15+00:00"
"time": "2025-04-12T22:26:52+00:00"
},
{
"name": "livewire/volt",
@ -3990,16 +3990,16 @@
},
{
"name": "spatie/laravel-package-tools",
"version": "1.92.0",
"version": "1.92.4",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-package-tools.git",
"reference": "dd46cd0ed74015db28822d88ad2e667f4496a6f6"
"reference": "d20b1969f836d210459b78683d85c9cd5c5f508c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/dd46cd0ed74015db28822d88ad2e667f4496a6f6",
"reference": "dd46cd0ed74015db28822d88ad2e667f4496a6f6",
"url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/d20b1969f836d210459b78683d85c9cd5c5f508c",
"reference": "d20b1969f836d210459b78683d85c9cd5c5f508c",
"shasum": ""
},
"require": {
@ -4010,6 +4010,7 @@
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.7|^8.0|^9.0|^10.0",
"pestphp/pest": "^1.23|^2.1|^3.1",
"phpunit/php-code-coverage": "^9.0|^10.0|^11.0",
"phpunit/phpunit": "^9.5.24|^10.5|^11.5",
"spatie/pest-plugin-test-time": "^1.1|^2.2"
},
@ -4038,7 +4039,7 @@
],
"support": {
"issues": "https://github.com/spatie/laravel-package-tools/issues",
"source": "https://github.com/spatie/laravel-package-tools/tree/1.92.0"
"source": "https://github.com/spatie/laravel-package-tools/tree/1.92.4"
},
"funding": [
{
@ -4046,7 +4047,7 @@
"type": "github"
}
],
"time": "2025-03-27T08:34:10+00:00"
"time": "2025-04-11T15:27:14+00:00"
},
{
"name": "spatie/temporary-directory",
@ -7360,16 +7361,16 @@
},
{
"name": "laravel/sail",
"version": "v1.41.0",
"version": "v1.41.1",
"source": {
"type": "git",
"url": "https://github.com/laravel/sail.git",
"reference": "fe1a4ada0abb5e4bd99eb4e4b0d87906c00cdeec"
"reference": "e5692510f1ef8e0f5096cde2b885d558f8d86592"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/sail/zipball/fe1a4ada0abb5e4bd99eb4e4b0d87906c00cdeec",
"reference": "fe1a4ada0abb5e4bd99eb4e4b0d87906c00cdeec",
"url": "https://api.github.com/repos/laravel/sail/zipball/e5692510f1ef8e0f5096cde2b885d558f8d86592",
"reference": "e5692510f1ef8e0f5096cde2b885d558f8d86592",
"shasum": ""
},
"require": {
@ -7419,7 +7420,7 @@
"issues": "https://github.com/laravel/sail/issues",
"source": "https://github.com/laravel/sail"
},
"time": "2025-01-24T15:45:36+00:00"
"time": "2025-04-22T13:39:39+00:00"
},
{
"name": "mockery/mockery",
@ -7665,16 +7666,16 @@
},
{
"name": "pestphp/pest",
"version": "v3.8.1",
"version": "v3.8.2",
"source": {
"type": "git",
"url": "https://github.com/pestphp/pest.git",
"reference": "6080f51a0b0830715c48ba0e7458b06907febfe5"
"reference": "c6244a8712968dbac88eb998e7ff3b5caa556b0d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pestphp/pest/zipball/6080f51a0b0830715c48ba0e7458b06907febfe5",
"reference": "6080f51a0b0830715c48ba0e7458b06907febfe5",
"url": "https://api.github.com/repos/pestphp/pest/zipball/c6244a8712968dbac88eb998e7ff3b5caa556b0d",
"reference": "c6244a8712968dbac88eb998e7ff3b5caa556b0d",
"shasum": ""
},
"require": {
@ -7761,7 +7762,7 @@
],
"support": {
"issues": "https://github.com/pestphp/pest/issues",
"source": "https://github.com/pestphp/pest/tree/v3.8.1"
"source": "https://github.com/pestphp/pest/tree/v3.8.2"
},
"funding": [
{
@ -7773,7 +7774,7 @@
"type": "github"
}
],
"time": "2025-04-03T16:35:58+00:00"
"time": "2025-04-17T10:53:02+00:00"
},
{
"name": "pestphp/pest-plugin",
@ -7847,16 +7848,16 @@
},
{
"name": "pestphp/pest-plugin-arch",
"version": "v3.1.0",
"version": "v3.1.1",
"source": {
"type": "git",
"url": "https://github.com/pestphp/pest-plugin-arch.git",
"reference": "ebec636b97ee73936ee8485e15a59c3f5a4c21b2"
"reference": "db7bd9cb1612b223e16618d85475c6f63b9c8daa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pestphp/pest-plugin-arch/zipball/ebec636b97ee73936ee8485e15a59c3f5a4c21b2",
"reference": "ebec636b97ee73936ee8485e15a59c3f5a4c21b2",
"url": "https://api.github.com/repos/pestphp/pest-plugin-arch/zipball/db7bd9cb1612b223e16618d85475c6f63b9c8daa",
"reference": "db7bd9cb1612b223e16618d85475c6f63b9c8daa",
"shasum": ""
},
"require": {
@ -7865,7 +7866,7 @@
"ta-tikoma/phpunit-architecture-test": "^0.8.4"
},
"require-dev": {
"pestphp/pest": "^3.7.5",
"pestphp/pest": "^3.8.1",
"pestphp/pest-dev-tools": "^3.4.0"
},
"type": "library",
@ -7901,7 +7902,7 @@
"unit"
],
"support": {
"source": "https://github.com/pestphp/pest-plugin-arch/tree/v3.1.0"
"source": "https://github.com/pestphp/pest-plugin-arch/tree/v3.1.1"
},
"funding": [
{
@ -7913,7 +7914,7 @@
"type": "github"
}
],
"time": "2025-03-30T17:28:50+00:00"
"time": "2025-04-16T22:59:48+00:00"
},
{
"name": "pestphp/pest-plugin-drift",
@ -7986,27 +7987,27 @@
},
{
"name": "pestphp/pest-plugin-laravel",
"version": "v3.1.0",
"version": "v3.2.0",
"source": {
"type": "git",
"url": "https://github.com/pestphp/pest-plugin-laravel.git",
"reference": "1c4e994476375c72aa7aebaaa97aa98f5d5378cd"
"reference": "6801be82fd92b96e82dd72e563e5674b1ce365fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pestphp/pest-plugin-laravel/zipball/1c4e994476375c72aa7aebaaa97aa98f5d5378cd",
"reference": "1c4e994476375c72aa7aebaaa97aa98f5d5378cd",
"url": "https://api.github.com/repos/pestphp/pest-plugin-laravel/zipball/6801be82fd92b96e82dd72e563e5674b1ce365fc",
"reference": "6801be82fd92b96e82dd72e563e5674b1ce365fc",
"shasum": ""
},
"require": {
"laravel/framework": "^11.39.1|^12.0.0",
"pestphp/pest": "^3.7.4",
"laravel/framework": "^11.39.1|^12.9.2",
"pestphp/pest": "^3.8.2",
"php": "^8.2.0"
},
"require-dev": {
"laravel/dusk": "^8.2.13|dev-develop",
"orchestra/testbench": "^9.9.0|^10.0.0",
"pestphp/pest-dev-tools": "^3.3.0"
"orchestra/testbench": "^9.9.0|^10.2.1",
"pestphp/pest-dev-tools": "^3.4.0"
},
"type": "library",
"extra": {
@ -8044,7 +8045,7 @@
"unit"
],
"support": {
"source": "https://github.com/pestphp/pest-plugin-laravel/tree/v3.1.0"
"source": "https://github.com/pestphp/pest-plugin-laravel/tree/v3.2.0"
},
"funding": [
{
@ -8056,7 +8057,7 @@
"type": "github"
}
],
"time": "2025-01-24T13:22:39+00:00"
"time": "2025-04-21T07:40:53+00:00"
},
{
"name": "pestphp/pest-plugin-mutate",
@ -8303,16 +8304,16 @@
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "5.6.1",
"version": "5.6.2",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8"
"reference": "92dde6a5919e34835c506ac8c523ef095a95ed62"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8",
"reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/92dde6a5919e34835c506ac8c523ef095a95ed62",
"reference": "92dde6a5919e34835c506ac8c523ef095a95ed62",
"shasum": ""
},
"require": {
@ -8361,9 +8362,9 @@
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"support": {
"issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.1"
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.2"
},
"time": "2024-12-07T09:39:29+00:00"
"time": "2025-04-13T19:20:35+00:00"
},
{
"name": "phpdocumentor/type-resolver",
@ -9822,16 +9823,16 @@
},
{
"name": "spatie/pest-expectations",
"version": "1.10.1",
"version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/pest-expectations.git",
"reference": "e498ebd92a1a9fb786656edf77fa569e9b39210e"
"reference": "6ec6e5184c70fe7113e4237d40ad4f8387ce1be2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/pest-expectations/zipball/e498ebd92a1a9fb786656edf77fa569e9b39210e",
"reference": "e498ebd92a1a9fb786656edf77fa569e9b39210e",
"url": "https://api.github.com/repos/spatie/pest-expectations/zipball/6ec6e5184c70fe7113e4237d40ad4f8387ce1be2",
"reference": "6ec6e5184c70fe7113e4237d40ad4f8387ce1be2",
"shasum": ""
},
"require": {
@ -9875,7 +9876,7 @@
],
"support": {
"issues": "https://github.com/spatie/pest-expectations/issues",
"source": "https://github.com/spatie/pest-expectations/tree/1.10.1"
"source": "https://github.com/spatie/pest-expectations/tree/1.11.0"
},
"funding": [
{
@ -9883,7 +9884,7 @@
"type": "github"
}
],
"time": "2025-03-12T19:34:55+00:00"
"time": "2025-04-13T12:30:30+00:00"
},
{
"name": "staabm/side-effects-detector",
@ -10011,23 +10012,23 @@
},
{
"name": "ta-tikoma/phpunit-architecture-test",
"version": "0.8.4",
"version": "0.8.5",
"source": {
"type": "git",
"url": "https://github.com/ta-tikoma/phpunit-architecture-test.git",
"reference": "89f0dea1cb0f0d5744d3ec1764a286af5e006636"
"reference": "cf6fb197b676ba716837c886baca842e4db29005"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ta-tikoma/phpunit-architecture-test/zipball/89f0dea1cb0f0d5744d3ec1764a286af5e006636",
"reference": "89f0dea1cb0f0d5744d3ec1764a286af5e006636",
"url": "https://api.github.com/repos/ta-tikoma/phpunit-architecture-test/zipball/cf6fb197b676ba716837c886baca842e4db29005",
"reference": "cf6fb197b676ba716837c886baca842e4db29005",
"shasum": ""
},
"require": {
"nikic/php-parser": "^4.18.0 || ^5.0.0",
"php": "^8.1.0",
"phpdocumentor/reflection-docblock": "^5.3.0",
"phpunit/phpunit": "^10.5.5 || ^11.0.0",
"phpunit/phpunit": "^10.5.5 || ^11.0.0 || ^12.0.0",
"symfony/finder": "^6.4.0 || ^7.0.0"
},
"require-dev": {
@ -10064,9 +10065,9 @@
],
"support": {
"issues": "https://github.com/ta-tikoma/phpunit-architecture-test/issues",
"source": "https://github.com/ta-tikoma/phpunit-architecture-test/tree/0.8.4"
"source": "https://github.com/ta-tikoma/phpunit-architecture-test/tree/0.8.5"
},
"time": "2024-01-05T14:10:56+00:00"
"time": "2025-04-20T20:23:40+00:00"
},
{
"name": "theseer/tokenizer",

View file

@ -35,7 +35,7 @@ new class extends Component {
@php
$current_image_uuid =$device->current_screen_image;
if($current_image_uuid) {
file_exists('storage/images/generated/' . $current_image_uuid . '.png') ? $file_extension = 'png' : $file_extension = 'bmp';
$file_extension = file_exists(storage_path('app/public/images/generated/' . $current_image_uuid . '.png')) ? 'png' : 'bmp';
$current_image_path = 'storage/images/generated/' . $current_image_uuid . '.' . $file_extension;
} else {
$current_image_path = 'storage/images/setup-logo.bmp';

View file

@ -211,7 +211,7 @@ new class extends Component {
@php
$current_image_uuid =$device->current_screen_image;
if($current_image_uuid) {
file_exists('storage/images/generated/' . $current_image_uuid . '.png') ? $file_extension = 'png' : $file_extension = 'bmp';
$file_extension = file_exists(storage_path('app/public/images/generated/' . $current_image_uuid . '.png')) ? 'png' : 'bmp';
$current_image_path = 'storage/images/generated/' . $current_image_uuid . '.' . $file_extension;
} else {
$current_image_path = 'storage/images/setup-logo.bmp';

View file

@ -73,7 +73,15 @@ Route::get('/display', function (Request $request) {
$image_path = 'images/setup-logo.bmp';
$filename = 'setup-logo.bmp';
} else {
$image_path = 'images/generated/'.$image_uuid.'.bmp';
if (file_exists(storage_path('app/public/images/generated/'.$image_uuid.'.bmp'))) {
$image_path = 'images/generated/'.$image_uuid.'.bmp';
$filename = basename($image_path);
} elseif (file_exists(storage_path('app/public/images/generated/'.$image_uuid.'.png'))) {
$image_path = 'images/generated/'.$image_uuid.'.png';
$filename = basename($image_path);
} else {
$image_path = 'images/generated/'.$image_uuid.'.bmp';
}
$filename = basename($image_path);
}

View file

@ -141,3 +141,146 @@ test('it only processes proxy cloud enabled devices', function () {
return $request->hasHeader('id', $disabledDevice->mac_address);
});
});
test('it fetches and processes proxy cloud responses for devices with BMP images', function () {
config(['services.trmnl.proxy_base_url' => 'https://example.com']);
// Create a test device with proxy cloud enabled
$device = Device::factory()->create([
'proxy_cloud' => true,
'mac_address' => '00:11:22:33:44:55',
'api_key' => 'test-api-key',
'last_rssi_level' => -70,
'last_battery_voltage' => 3.7,
'default_refresh_interval' => 300,
'last_firmware_version' => '1.0.0',
]);
// Mock the API response with BMP image
Http::fake([
config('services.trmnl.proxy_base_url').'/api/display' => Http::response([
'image_url' => 'https://example.com/test-image.bmp?response-content-type=image/bmp',
'filename' => 'test-image',
]),
'https://example.com/test-image.bmp?response-content-type=image/bmp' => Http::response('fake-image-content'),
]);
// Run the job
$job = new FetchProxyCloudResponses;
$job->handle();
// Assert HTTP requests were made with correct headers
Http::assertSent(function ($request) use ($device) {
return $request->hasHeader('id', $device->mac_address) &&
$request->hasHeader('access-token', $device->api_key) &&
$request->hasHeader('width', 800) &&
$request->hasHeader('height', 480) &&
$request->hasHeader('rssi', $device->last_rssi_level) &&
$request->hasHeader('battery_voltage', $device->last_battery_voltage) &&
$request->hasHeader('refresh-rate', $device->default_refresh_interval) &&
$request->hasHeader('fw-version', $device->last_firmware_version);
});
// Assert the device was updated
$device->refresh();
expect($device->current_screen_image)->toBe('test-image')
->and($device->proxy_cloud_response)->toBe([
'image_url' => 'https://example.com/test-image.bmp?response-content-type=image/bmp',
'filename' => 'test-image',
]);
// Assert the image was saved with BMP extension
expect(Storage::disk('public')->exists('images/generated/test-image.bmp'))->toBeTrue();
expect(Storage::disk('public')->exists('images/generated/test-image.png'))->toBeFalse();
});
test('it fetches and processes proxy cloud responses for devices with PNG images', function () {
config(['services.trmnl.proxy_base_url' => 'https://example.com']);
// Create a test device with proxy cloud enabled
$device = Device::factory()->create([
'proxy_cloud' => true,
'mac_address' => '00:11:22:33:44:55',
'api_key' => 'test-api-key',
'last_rssi_level' => -70,
'last_battery_voltage' => 3.7,
'default_refresh_interval' => 300,
'last_firmware_version' => '1.0.0',
]);
// Mock the API response with PNG image
Http::fake([
config('services.trmnl.proxy_base_url').'/api/display' => Http::response([
'image_url' => 'https://example.com/test-image.png?response-content-type=image/png',
'filename' => 'test-image',
]),
'https://example.com/test-image.png?response-content-type=image/png' => Http::response('fake-image-content'),
]);
// Run the job
$job = new FetchProxyCloudResponses;
$job->handle();
// Assert HTTP requests were made with correct headers
Http::assertSent(function ($request) use ($device) {
return $request->hasHeader('id', $device->mac_address) &&
$request->hasHeader('access-token', $device->api_key) &&
$request->hasHeader('width', 800) &&
$request->hasHeader('height', 480) &&
$request->hasHeader('rssi', $device->last_rssi_level) &&
$request->hasHeader('battery_voltage', $device->last_battery_voltage) &&
$request->hasHeader('refresh-rate', $device->default_refresh_interval) &&
$request->hasHeader('fw-version', $device->last_firmware_version);
});
// Assert the device was updated
$device->refresh();
expect($device->current_screen_image)->toBe('test-image')
->and($device->proxy_cloud_response)->toBe([
'image_url' => 'https://example.com/test-image.png?response-content-type=image/png',
'filename' => 'test-image',
]);
// Assert the image was saved with PNG extension
expect(Storage::disk('public')->exists('images/generated/test-image.png'))->toBeTrue();
expect(Storage::disk('public')->exists('images/generated/test-image.bmp'))->toBeFalse();
});
test('it handles missing content type in image URL gracefully', function () {
config(['services.trmnl.proxy_base_url' => 'https://example.com']);
// Create a test device with proxy cloud enabled
$device = Device::factory()->create([
'proxy_cloud' => true,
'mac_address' => '00:11:22:33:44:55',
'api_key' => 'test-api-key',
]);
// Mock the API response with no content type in URL
Http::fake([
config('services.trmnl.proxy_base_url').'/api/display' => Http::response([
'image_url' => 'https://example.com/test-image.bmp',
'filename' => 'test-image',
]),
'https://example.com/test-image.bmp' => Http::response('fake-image-content'),
]);
// Run the job
$job = new FetchProxyCloudResponses;
$job->handle();
// Assert the device was updated
$device->refresh();
expect($device->current_screen_image)->toBe('test-image')
->and($device->proxy_cloud_response)->toBe([
'image_url' => 'https://example.com/test-image.bmp',
'filename' => 'test-image',
]);
// Assert the image was saved with default BMP extension
expect(Storage::disk('public')->exists('images/generated/test-image.bmp'))->toBeTrue();
expect(Storage::disk('public')->exists('images/generated/test-image.png'))->toBeFalse();
});