Deploy Ladill Events / deploy (push) Successful in 28s
Proxy registration transaction paths on Events, add a join button on the confirmation page, introduce speaker roster management, and replace the QR design wizard with merchant-style create/show flows. Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Support\LadillLink;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
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(), '/'))) {
|
|
return $next($request);
|
|
}
|
|
|
|
if (LadillLink::isInternalRequest($request)) {
|
|
return $next($request);
|
|
}
|
|
|
|
if ($this->servesStoredAsset($request) || $this->servesRegistrationTransaction($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);
|
|
}
|
|
|
|
private function servesRegistrationTransaction(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));
|
|
|
|
return $suffix === 'register'
|
|
|| str_starts_with($suffix, 'register/')
|
|
|| str_starts_with($suffix, 'registered/');
|
|
}
|
|
}
|