Display CMS Optimierungen 03-06-2026

This commit is contained in:
Kevin Adametz 2026-06-03 15:43:18 +02:00
parent 6c6d683b9a
commit bebfa63e87
17 changed files with 925 additions and 133 deletions

View file

@ -0,0 +1,71 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
class DisplayQrCodeService
{
/**
* @return array{path: string, url: string}|null
*/
public function generateForUrl(?string $url): ?array
{
$normalizedUrl = $this->normalizeUrl($url);
if ($normalizedUrl === '') {
return null;
}
$path = 'display-qr-codes/'.sha1($normalizedUrl).'.png';
$disk = Storage::disk('public');
if (! $disk->exists($path)) {
try {
$response = Http::timeout(10)
->retry(2, 300)
->get($this->remoteQrUrl($normalizedUrl));
if (! $response->successful() || $response->body() === '') {
return null;
}
$disk->put($path, $response->body());
} catch (\Throwable) {
return null;
}
}
return [
'path' => $path,
'url' => asset('storage/'.$path),
];
}
public function normalizeUrl(?string $url): string
{
$url = trim((string) $url);
if ($url === '') {
return '';
}
if (str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) {
return $url;
}
return 'https://'.$url;
}
private function remoteQrUrl(string $url): string
{
return 'https://api.qrserver.com/v1/create-qr-code/?'.http_build_query([
'size' => '300x300',
'margin' => '8',
'color' => '000000',
'bgcolor' => 'ffffff',
'data' => $url,
]);
}
}