Fix event branding images broken by legacy QR redirect.
Deploy Ladill Events / deploy (push) Successful in 25s
Deploy Ladill Events / deploy (push) Successful in 25s
Keep logo and cover asset URLs on Events instead of redirecting them to ladl.link, which does not serve uploaded QR storage files. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,6 +9,23 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectLegacyQrToLadillLink
|
||||
{
|
||||
/** @var list<string> */
|
||||
private const STORAGE_ASSET_SUFFIXES = [
|
||||
'event-logo',
|
||||
'event-cover',
|
||||
'itinerary-cover',
|
||||
'business-logo',
|
||||
'business-cover',
|
||||
'menu-logo',
|
||||
'menu-cover',
|
||||
'church-logo',
|
||||
'church-cover',
|
||||
'book-cover',
|
||||
'vcard-avatar',
|
||||
'app-icon',
|
||||
'file',
|
||||
];
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (! preg_match('#^q/[a-z0-9]#i', ltrim($request->path(), '/'))) {
|
||||
@@ -19,6 +36,32 @@ class RedirectLegacyQrToLadillLink
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($this->servesStoredAsset($request)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return LadillLink::legacyRedirect($request);
|
||||
}
|
||||
|
||||
private function servesStoredAsset(Request $request): bool
|
||||
{
|
||||
$shortCode = $request->route('shortCode');
|
||||
if (! is_string($shortCode) || $shortCode === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = ltrim($request->path(), '/');
|
||||
$prefix = 'q/'.$shortCode.'/';
|
||||
if (! str_starts_with($path, $prefix)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$suffix = substr($path, strlen($prefix));
|
||||
|
||||
if (in_array($suffix, self::STORAGE_ASSET_SUFFIXES, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) preg_match('#^(image/\d+|item-image/\d+/\d+)$#', $suffix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\RedirectLegacyQrToLadillLink;
|
||||
use App\Support\LadillLink;
|
||||
use Illuminate\Http\Request;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LegacyQrRedirectTest extends TestCase
|
||||
{
|
||||
public function test_event_branding_assets_are_not_redirected_to_ladill_link(): void
|
||||
{
|
||||
$middleware = new RedirectLegacyQrToLadillLink;
|
||||
|
||||
foreach (['event-logo', 'event-cover', 'itinerary-cover'] as $suffix) {
|
||||
$request = Request::create('/q/demo-event/'.$suffix, 'GET');
|
||||
$request->setRouteResolver(function () use ($request) {
|
||||
return new class($request)
|
||||
{
|
||||
public function __construct(private Request $request) {}
|
||||
|
||||
public function parameter(string $name): ?string
|
||||
{
|
||||
return $name === 'shortCode' ? 'demo-event' : null;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
$response = $middleware->handle($request, fn () => response('ok'));
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
$this->assertSame('ok', $response->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_public_event_pages_still_redirect_to_ladill_link(): void
|
||||
{
|
||||
config(['link.public_domain' => 'ladl.link']);
|
||||
|
||||
$response = $this->get('/q/demo-event');
|
||||
|
||||
$response->assertRedirect(LadillLink::url('demo-event'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user